继承我的问题。我试图在服务器上运行以下应用程序:https://github.com/googleads/aw-reporting,我按照自述文件,将项目导入我的Eclipse并制作了一个带有选项的Runnable Jar,该选项还创建了一个包含所有Jars的lib文件夹。现在当我在我的机器上运行jar时一切正常,但是我将jar和lib文件夹上传到我的服务器(两台机器都运行在linux上),我一直收到这个错误:
2014-04-11 04:21:45,467 [ERROR|com.google.api.ads.adwords.jaxws.extensions.AwReporting|AwReporting] Unexpected error accessing the API: Error creating bean with name 'sqlAuthTokenPersister' defined in URL [jar:file:/home/rst_ericg/aw-reporting/aw-report.jar!/com/google/api/ads/adwords/jaxws/extensions/report/model/persistence/sql/SqlAuthTokenPersister.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [aw-report-sql-beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [aw-report-sql-beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlAuthTokenPersister' defined in URL [jar:file:/home/rst_ericg/aw-reporting/aw-report.jar!/com/google/api/ads/adwords/jaxws/extensions/report/model/persistence/sql/SqlAuthTokenPersister.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [aw-report-sql-beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [aw-report-sql-beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1051)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:955)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.google.api.ads.adwords.jaxws.extensions.AwReporting.initApplicationContextAndProperties(AwReporting.java:438)
at com.google.api.ads.adwords.jaxws.extensions.AwReporting.main(AwReporting.java:126)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate4.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in class path resource [aw-report-sql-beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:578)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1338)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:356)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:895)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
... 16 more
Caused by: java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:260)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:416)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1290)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1261)
... 26 more
我仔细检查了lib文件夹,包含org.springframework.orm.hibernate4.LocalSessionFactoryBean
的jar就在那里,但不知怎的,他找不到它,它是完全相同的文件夹,在我的电脑上工作正常。
清单 - 版本:1.0 类路径:。 aw-report_lib / javax.inject-1.jar aw-report_lib / jdo2-api- 2.3-eb.jar aw-report_lib / transaction-api-1.1.jar aw-report_lib / servle t-api-2.5.jar aw-report_lib / spring-beans-3.2.2.RELEASE.jar aw-report_ lib / spring-core-3.2.2.RELEASE.jar aw-report_lib / commons-logging-1.1.1 .jar aw-report_lib / spring-context-3.2.2.RELEASE.jar aw-report_lib / spr ing-aop-3.2.2.RELEASE.jar aw-report_lib / aopalliance-1.0.jar aw-report _lib / spring-expression-3.2.2.RELEASE.jar aw-report_lib / spring-tx-3.2。 2.RELEASE.jar aw-report_lib / spring-orm-3.2.2.RELEASE.jar aw-report_li b / spring-jdbc-3.2.2.RELEASE.jar aw-report_lib / hibernate-core-4.2.1.Fi nal.jar aw-report_lib / antlr-2.7.7.jar aw-report_lib / jboss-logging-3.1 .0.GA.jar aw-report_lib / dom4j-1.6.1.jar aw-report_lib / jboss-transacti on-api_1.1_spec-1.0.1.Final.jar aw-report_lib / hibernate-jpa-2.0-api-1 .0.1.Final.jar aw-report_lib / javassist-3.15.0-GA.jar aw-report_lib / hi bernate-commons-annotations-4.0.1.Final.jar aw-report_lib / joda-time-2 .2.jar aw-report_lib / opencsv-2.3.jar aw-report_lib / gson-2.2.4.jar aw- report_lib / guava-jdk5-16.0-rc1.jar aw-report_lib / ads-lib-1.26.0.jar a w-report_lib / guice-3.0.jar aw-report_lib / guice-assistedinject-3.0.jar aw-report_lib / guice-multibindings-3.0.jar aw-report_lib / commons-conf iguration-1.7.jar aw-report_lib / commons-collections-3.2.1.jar aw-repo rt_lib / commons-lang-2.5.jar aw-report_lib / commons-digester-1.8.1.jar aw-report_lib / commons-beanutils-1.8.3.jar aw-report_lib / slf4j-api-1.6 .1.jar aw-report_lib / google-api-client-1.17.0-rc.jar aw-report_lib / go ogle-oauth-client-1.17.0-rc.jar aw-report_lib / google-http-client-1.17 .0-rc.jar aw-report_lib / jsr305-1.3.9.jar aw-report_lib / httpclient-4.0 .1.jar aw-report_lib / httpcore-4.0.1.jar aw-report_lib / commons-codec-1 .3.jar aw-report_lib / google-http-client-jackson2-1.17.0-rc.jar aw-rep ort_lib / jackson-core-2.1.3.jar aw-report_lib / junit-4.10.jar aw-report _lib / hamcrest-core-1.1.jar aw-report_lib / spring-test-3.2.2.RELEASE.ja r aw-report_lib / h2-1.3.172.jar aw-report_lib / mysql-connector-java-5.1 .jar aw-report_lib / jtds-1.3.0.jar aw-report_lib / mongo-java-driver-2 .11.0.jar aw-report_lib / objectify-4.0.jar aw-report_lib / guava-14.0.1。 jar aw-report_lib / guava-16.0-rc1.jar aw-report_lib / adwords-appengine- 1.26.0.jar aw-report_lib / ads-lib-appengine-1.26.0.jar aw-report_lib / g oogle-api-client-appengine-1.17.0-rc.jar aw-report_lib / google-oauth-c lient-appengine-1.17.0-rc.jar aw-report_lib / google-http-client-appeng ine-1.17.0-rc.jar aw-report_lib / google-oauth-client-servlet-1.17.0-rc .jar aw-report_lib / google-http-client-jdo-1.17.0-rc.jar aw-report_lib /google-api-client-servlet-1.17.0-rc.jar aw-report_lib / log4j-1.2.17.j ar aw-report_lib / jmustache-1.8.jar aw-report_lib / core-renderer-R8.jar aw-report_lib / itext-2.0.8.jar aw-report_lib / bcmail-jdk14-138.jar aw- report_lib / bcprov-jdk14-138.jar aw-report_lib / commons-io-1.3.2.jar aw -report_lib / commons-cli-1.2.jar aw-report_lib / mockito-all-1.8.5.jar a W-report_lib /谷歌的API服务驱动-V2-rev113-1.17.0-rc.jar Main-Class:com.google.api.ads.adwords.jaxws.extensions.AwReporting
答案 0 :(得分:0)
作为您的方法的替代方案,也可能解决您的问题,我建议您添加一个Maven插件(如果您使用的是Maven),它会自动将您的应用及其所有依赖项打包到一个可执行jar文件中。
只需将Maven Assembly插件添加到插件列表中,然后运行 mvn package 目标。就是这样,你得到了完全包装的可执行jar +没有依赖的原始jar。
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.mypackage.RunApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>