我正在使用OneJar Maven Plugin在单个 jar 包中创建一个带有 Embedded jetty 的 Spring 应用程序。它是一个 api,用于服务由 Apache Hbase 支持的请求。它编译罚款但是当我运行它时:
$ java -jar target/myapp.one-jar.jar
JarClassLoader: Warning: Null manifest from input stream associated with: lib/javax.inject-1.jar
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/ArrayStack.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap$Values.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap$CollectionView$CollectionViewIterator.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap$1.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/BufferUnderflowException.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap$KeySet.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap$CollectionView.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/collections/FastHashMap$EntrySet.class in lib/commons-beanutils-1.7.0.jar is hidden by lib/commons-collections-3.2.1.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/beanutils/BasicDynaBean.class in lib/commons-beanutils-core-1.8.0.jar is hidden by lib/commons-beanutils-1.7.0.jar (with different bytecode)
JarClassLoader: Warning: org/apache/commons/beanutils/BasicDynaClass.class in lib/commons-beanutils-core-1.8.0.jar is hidden by lib/commons-beanutils-1.7.0.jar (with different bytecode)
然后,当 Spring 上下文初始化时,我得到了这个堆栈跟踪
13/09/08 18:57:06 ERROR context.ContextLoader: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hConnection' defined in class com.example.myapp.context.Config: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.apache.hadoop.hbase.client.HConnection com.example.myapp.context.Config.hConnection() throws java.lang.Exception] threw exception; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1025)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:921)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
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)
这两个有关系吗?我该如何解决?这是我构建的 hConnection bean:
@Bean
@Named("hConnection")
public HConnection hConnection() throws Exception {
org.apache.hadoop.conf.Configuration configuration = new org.apache.hadoop.conf.Configuration();
HConnection hConnection = HConnectionManager.createConnection(configuration);
HTableInterface hTableInterface = hConnection.getTable("mytable");
hTableInterface.close();
return hConnection;
}
我必须为 Hadoop 配置使用完全限定的包名称,因为它与org.springframework.context.annotation.Configuration
注释冲突。
HConnection 的相关单元测试通过mvn test
:
public class HConnectionTest {
@Test
public void testHConnection() throws Exception {
Configuration configuration = new Configuration();
HConnection hConnection = HConnectionManager.createConnection(configuration);
Assert.assertEquals(hConnection.getClass().getSimpleName(),"HConnectionImplementation");
HTableInterface hTableInterface = hConnection.getTable("__test__");
Put put = new Put(Bytes.toBytes("__test__"));
put.add(Bytes.toBytes("source"), Bytes.toBytes("__test__"),Bytes.toBytes("__test__"));
hTableInterface.put(put);
Get get = new Get(Bytes.toBytes("__test__"));
Result result = hTableInterface.get(get);
byte [] value = result.getValue(Bytes.toBytes("source"), Bytes.toBytes("__test__"));
String valueStr = Bytes.toString(value);
Assert.assertEquals(valueStr, "__test__");
}
}
在我看来,这些JarClassLoader
警告也与此有关。我想知道我是否应该排除某些包裹?顺便说一句,这是
Hadoop 1.2.1
Hbase 0.94.11
Java 1.7.0_25
Mac OS X 10.8.4
更新:问题仍然存在,但偶然发现我的 Apache cxf 版本错误。我需要 2.7.2,但有 2.7.5。我尝试将我的 HBase Connection 实例化移动到它自己的类,而不是 Spring Annotation 配置。从某种意义上说,这有助于解决这种情况,我现在可以运行我的应用程序并 ping 健康检查,但我仍然无法连接到 HBase。当我请求使用我的 HBase 连接的 URL 时,我得到以下堆栈跟踪:
2013-09-09 03:05:52,476 WARN [||] [org.apache.cxf.phase.PhaseInterceptorChain] (qtp2108992104-28:) - Application {http://api.myapp.example.com/}HealthCheck has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not initialize class com.example.myapp.service.HbaseSubmissionService
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162) ~[cxf-api-2.7.2.jar:2.7.2]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128) ~[cxf-api-2.7.2.jar:2.7.2]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) ~[cxf-rt-frontend-jaxrs-2.7.2.jar:2.7.2]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:102) ~[cxf-rt-frontend-jaxrs-2.7.2.jar:2.7.2]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58) ~[cxf-api-2.7.2.jar:2.7.2]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94) ~[cxf-api-2.7.2.jar:2.7.2]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) ~[cxf-api-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[cxf-api-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:218) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:163) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:137) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:158) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:243) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:168) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735) ~[javax.servlet-3.0.0.v201112011016.jar:na]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:219) ~[cxf-rt-transports-http-2.7.2.jar:2.7.2]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) ~[jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505) ~[jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) ~[jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.Server.handle(Server.java:445) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224) ~[jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) ~[jetty-io-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) ~[jetty-util-9.0.4.v20130625.jar:9.0.4.v20130625]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) ~[jetty-util-9.0.4.v20130625.jar:9.0.4.v20130625]
at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
...由于 SO 长度限制而省略了一些堆栈跟踪
对我来说不太有意义的错误的一部分是:
13/09/09 03:29:55 FATAL conf.Configuration: error parsing conf file: java.io.FileNotFoundException: /target/myapp.one-jar.jar (No such file or directory)
我还不明白什么代码或包试图解析实际的 jar?这意味着什么?我认为这可能是 Hadoop 在类路径上寻找其配置文件,但我的类路径包括
~/Hadoop/lib//hadoop/conf:~/Hadoop/lib/hbase/conf
这是我保存 Hadoop 和 Hbase 配置文件的地方。看起来像罪魁祸首的部分是我的 HBaseConnection 类的初始化:
Could not initialize class com.example.myapp.service.HbaseSubmissionService
更新:这是结果mvn dependency:tree
[INFO] com.example.myapp:jar:0.1.0
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxrs:jar:2.7.2:compile
[INFO] | +- org.apache.cxf:cxf-api:jar:2.7.2:compile
[INFO] | | +- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.4:runtime
[INFO] | | | \- org.codehaus.woodstox:stax2-api:jar:3.1.1:runtime
[INFO] | | +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.3:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO] | | \- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO] | +- org.apache.cxf:cxf-rt-core:jar:2.7.2:compile
[INFO] | | \- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
[INFO] | +- javax.ws.rs:javax.ws.rs-api:jar:2.0-m10:compile
[INFO] | +- org.apache.cxf:cxf-rt-bindings-xml:jar:2.7.2:compile
[INFO] | \- org.apache.cxf:cxf-rt-transports-http:jar:2.7.2:compile
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:2.7.2:compile
[INFO] | +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] | +- asm:asm:jar:3.3.1:compile
[INFO] | +- org.apache.cxf:cxf-rt-bindings-soap:jar:2.7.2:compile
[INFO] | | \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.7.2:compile
[INFO] | +- org.apache.cxf:cxf-rt-frontend-simple:jar:2.7.2:compile
[INFO] | \- org.apache.cxf:cxf-rt-ws-addr:jar:2.7.2:compile
[INFO] | \- org.apache.cxf:cxf-rt-ws-policy:jar:2.7.2:compile
[INFO] | \- org.apache.neethi:neethi:jar:3.0.2:compile
[INFO] +- org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.12:compile
[INFO] +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.12:compile
[INFO] +- org.codehaus.jackson:jackson-xc:jar:1.9.12:compile
[INFO] +- org.springframework:spring-core:jar:3.2.4.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-context:jar:3.2.4.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:3.2.4.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-beans:jar:3.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:3.2.4.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:3.2.4.RELEASE:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.13:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.0.13:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- net.sf.opencsv:opencsv:jar:2.3:compile
[INFO] +- javax.inject:javax.inject:jar:1:compile
[INFO] +- org.eclipse.jetty:jetty-server:jar:9.0.4.v20130625:compile
[INFO] | +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
[INFO] | +- org.eclipse.jetty:jetty-http:jar:9.0.4.v20130625:compile
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.0.4.v20130625:compile
[INFO] | \- org.eclipse.jetty:jetty-io:jar:9.0.4.v20130625:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.0.4.v20130625:compile
[INFO] | +- org.eclipse.jetty:jetty-xml:jar:9.0.4.v20130625:compile
[INFO] | \- org.eclipse.jetty:jetty-servlet:jar:9.0.4.v20130625:compile
[INFO] | \- org.eclipse.jetty:jetty-security:jar:9.0.4.v20130625:compile
[INFO] +- commons-beanutils:commons-beanutils-core:jar:1.8.3:compile
[INFO] +- org.apache.hbase:hbase:jar:0.94.11:compile
[INFO] | +- com.yammer.metrics:metrics-core:jar:2.1.2:compile
[INFO] | +- com.google.guava:guava:jar:11.0.2:compile
[INFO] | | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | +- commons-cli:commons-cli:jar:1.2:compile
[INFO] | +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | \- commons-digester:commons-digester:jar:1.8:compile
[INFO] | | \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] | +- com.github.stephenc.high-scale-lib:high-scale-lib:jar:1.1.1:compile
[INFO] | +- commons-codec:commons-codec:jar:1.4:compile
[INFO] | +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] | +- commons-io:commons-io:jar:2.1:compile
[INFO] | +- commons-lang:commons-lang:jar:2.5:compile
[INFO] | +- log4j:log4j:jar:1.2.16:compile
[INFO] | +- org.apache.avro:avro:jar:1.5.3:compile
[INFO] | | \- org.xerial.snappy:snappy-java:jar:1.0.3.2:compile
[INFO] | +- org.apache.avro:avro-ipc:jar:1.5.3:compile
[INFO] | | +- org.jboss.netty:netty:jar:3.2.4.Final:compile
[INFO] | | \- org.apache.velocity:velocity:jar:1.7:compile
[INFO] | +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
[INFO] | +- org.apache.thrift:libthrift:jar:0.8.0:compile
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.1.3:compile
[INFO] | +- org.jruby:jruby-complete:jar:1.6.5:compile
[INFO] | +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] | +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] | +- org.mortbay.jetty:jsp-2.1:jar:6.1.14:compile
[INFO] | +- org.mortbay.jetty:jsp-api-2.1:jar:6.1.14:compile
[INFO] | +- org.mortbay.jetty:servlet-api-2.5:jar:6.1.14:compile
[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.4.3:compile
[INFO] | +- org.jamon:jamon-runtime:jar:2.3.1:compile
[INFO] | +- com.google.protobuf:protobuf-java:jar:2.4.0a:compile
[INFO] | +- com.sun.jersey:jersey-core:jar:1.8:compile
[INFO] | +- com.sun.jersey:jersey-json:jar:1.8:compile
[INFO] | | \- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] | +- com.sun.jersey:jersey-server:jar:1.8:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.1:compile
[INFO] | | \- javax.activation:activation:jar:1.1:compile
[INFO] | \- stax:stax-api:jar:1.0.1:compile
[INFO] \- org.apache.hadoop:hadoop-core:jar:1.2.1:compile
[INFO] +- xmlenc:xmlenc:jar:0.52:compile
[INFO] +- org.apache.commons:commons-math:jar:2.1:compile
[INFO] +- commons-net:commons-net:jar:1.4.1:compile
[INFO] +- tomcat:jasper-runtime:jar:5.5.23:compile
[INFO] +- tomcat:jasper-compiler:jar:5.5.23:compile
[INFO] +- commons-el:commons-el:jar:1.0:compile
[INFO] +- net.java.dev.jets3t:jets3t:jar:0.6.1:compile
[INFO] +- hsqldb:hsqldb:jar:1.8.0.10:compile
[INFO] +- oro:oro:jar:2.0.8:compile
[INFO] \- org.eclipse.jdt:core:jar:3.1.1:compile