2013-04-11 60 views
2

我终于能够在我的Java应用程序中创建一个服务器实例,该实例使用嵌入式数据库,如here所解释的。这在我从Eclipse运行它时正常工作,但这实际上并不是我的目的(我的应用程序在其他事物之间为数据库提供新节点和关系)。我有一个应该是我的服务器实例的Neo4j盒子,我想将我的应用程序部署为JAR文件。这样,我想从那里访问Web界面。我已经测试过它:在开发机器上运行Java应用程序时,同一专用网络中的任何机器都可以毫无问题地访问该接口。尝试将所有内容打包到JAR中进行服务器分发时都会出现问题。Spring Data Neo4j:使用带有嵌入式JAR包装的Neo4j服务器

具体错误堆栈如下:

<!-- bean initialization stuff --> 

Apr 11, 2013 1:14:30 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery 
INFO: Non clean shutdown detected on log [/data/production/graph.db/nioneo_logical.log.2]. Recovery started ... 
Apr 11, 2013 1:14:32 PM org.neo4j.kernel.impl.transaction.xaframework.XaLogicalLog doInternalRecovery 
INFO: Non clean shutdown detected on log [/data/production/graph.db/index/lucene.log.2]. Recovery started ... 
2013-04-11 13:14:34,787 INFO [org.springframework.transaction.jta.JtaTransactionManager] - Using JTA UserTransaction: [email protected] 
2013-04-11 13:14:34,787 INFO [org.springframework.transaction.jta.JtaTransactionManager] - Using JTA TransactionManager: [email protected]c08 
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log 
INFO: Starting Neo Server on port [7474] with [40] threads available 
Logger not configured, logging to std out instead: [FINE] Adding JAXRS packages [org.neo4j.server.rest.discovery] at [/] 
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log 
INFO: Mounted discovery module at [/] 
Logger not configured, logging to std out instead: [FINE] Adding JAXRS packages [org.neo4j.server.rest.web] at [/db/data] 
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log 
INFO: Mounted REST API at [/db/data] 
Logger not configured, logging to std out instead: [FINE] Adding JAXRS packages [org.neo4j.server.webadmin.rest] at [/db/manage] 
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log 
INFO: Mounted management API at [/db/manage] 
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log 
INFO: Mounted webadmin at [/webadmin] 
2013-04-11 13:14:35,494 INFO [org.mortbay.log] - Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog 
Apr 11, 2013 1:14:35 PM org.neo4j.server.logging.Logger log 
INFO: Mounting static content at [/webadmin] from [webadmin-html] 
Logger not configured, logging to std out instead: [FINE] Found [jar:file:/home/jaranda/cicerone/cicerone-crawlers/target/cicerone-crawlers-0.0.1-SNAPSHOT.jar!/webadmin-html] 
Logger not configured, logging to std out instead: [FINE] Mounting static content from [jar:file:/home/jaranda/cicerone/cicerone-crawlers/target/cicerone-crawlers-0.0.1-SNAPSHOT.jar!/webadmin-html] at [/webadmin] 
Logger not configured, logging to std out instead: [FINE] Mounting servlet at [/db/manage] 
Logger not configured, logging to std out instead: [FINE] Mounting servlet at [/db/data] 
Logger not configured, logging to std out instead: [FINE] Mounting servlet at [/] 
2013-04-11 13:14:35,556 INFO [org.mortbay.log] - jetty-6.1.x 
2013-04-11 13:14:35,915 INFO [org.mortbay.log] - NO JSP Support for /webadmin, did not find org.apache.jasper.servlet.JspServlet 
Apr 11, 2013 1:14:36 PM com.sun.jersey.api.core.PackagesResourceConfig init 
INFO: Scanning for root resource and provider classes in the packages: 
    org.neo4j.server.webadmin.rest 
Apr 11, 2013 1:14:39 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses 
INFO: Root resource classes found: 
    class org.neo4j.server.webadmin.rest.JmxService 
    class org.neo4j.server.webadmin.rest.ConsoleService 
    class org.neo4j.server.webadmin.rest.MonitorService 
    class org.neo4j.server.webadmin.rest.RootService 
Apr 11, 2013 1:14:39 PM com.sun.jersey.api.core.ScanningResourceConfig init 
INFO: No provider classes found. 
Apr 11, 2013 1:14:39 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate 
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM' 
Apr 11, 2013 1:14:40 PM com.sun.jersey.api.core.PackagesResourceConfig init 
INFO: Scanning for root resource and provider classes in the packages: 
    org.neo4j.server.rest.web 
Apr 11, 2013 1:14:43 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses 
INFO: Root resource classes found: 
    class org.neo4j.server.rest.web.ResourcesService 
    class org.neo4j.server.rest.web.RestfulGraphDatabase 
    class org.neo4j.server.rest.web.DatabaseMetadataService 
    class org.neo4j.server.rest.web.ExtensionService 
    class org.neo4j.server.rest.web.CypherService 
    class org.neo4j.server.rest.web.BatchOperationService 
Apr 11, 2013 1:14:43 PM com.sun.jersey.api.core.ScanningResourceConfig init 
INFO: No provider classes found. 
Apr 11, 2013 1:14:43 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate 
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM' 
Apr 11, 2013 1:14:43 PM com.sun.jersey.api.core.PackagesResourceConfig init 
INFO: Scanning for root resource and provider classes in the packages: 
    org.neo4j.server.rest.discovery 
Apr 11, 2013 1:14:46 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses 
INFO: Root resource classes found: 
    class org.neo4j.server.rest.discovery.DiscoveryService 
Apr 11, 2013 1:14:46 PM com.sun.jersey.api.core.ScanningResourceConfig init 
INFO: No provider classes found. 
Apr 11, 2013 1:14:46 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate 
INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 11:17 AM' 
2013-04-11 13:14:46,751 INFO [org.mortbay.log] - Started [email protected]:7474 
Apr 11, 2013 1:14:46 PM org.neo4j.server.logging.Logger log 
INFO: Server started on [http://172.20.100.33:7474/] 
2013-04-11 13:14:47,616 INFO [org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler] - Initializing ExecutorService 'taskScheduler' 
2013-04-11 13:14:47,714 INFO [com.twitter.hbc.httpclient.BasicClient] - New connection executed: Hosebird-Client-02, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true 
2013-04-11 13:14:48,346 INFO [com.twitter.hbc.httpclient.ClientBase] - Hosebird-Client-02 Establishing a connection 
Apr 11, 2013 1:14:48 PM com.sun.jersey.spi.container.ContainerResponse write 
SEVERE: A message body writer for Java class [B, and Java type class [B, and MIME media type application/json was not found 
Apr 11, 2013 1:14:48 PM com.sun.jersey.spi.container.ContainerResponse write 
SEVERE: The registered message body writers compatible with the MIME media type are: 
*/* -> 
    com.sun.jersey.server.impl.template.ViewableMessageBodyWriter 

Apr 11, 2013 1:14:48 PM com.sun.jersey.spi.container.ContainerResponse logException 
SEVERE: Mapped exception to response: 500 (Internal Server Error) 
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class [B, and Java type class [B, and MIME media type application/json was not found 
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) 
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) 
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390) 
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) 
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 
    at org.mortbay.jetty.Server.handle(Server.java:326) 
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926) 
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549) 
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) 
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) 
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) 
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class [B, and Java type class [B, and MIME media type application/json was not found 
    ... 22 more 

我必须说,我是相当新的春天,Maven和Neo4j的本身。我很失落如何摆脱这个问题。 Web界面实际上加载但没有任何功能。见附加镜头:

Neo4j web interface with no functionality

我的应用程序的后端工作正常,尽管存在此问题并且实际上创建了新的节点/关系。

我认为这个问题(或种)已被讨论here但我的答案并不清楚。

有什么建议吗?先谢谢你!

回答

4

我终于找到了一个解决方案,它做到了。我只是分享它,以防其他人遇到同样的问题。问题在于,在jar打包过程中,META-INF/services下的一些文件被覆盖,因为默认情况下它们的内容没有被合并。据行家荫插件参考:

提供一些接口的实现

JAR文件往往与 推出一款META-INF /服务/目录由服务定位器映射接口,其 实现类查询。到合并 相同的接口的多个实现为一个服务入口, 的ServicesResourceTransformer都可以使用。

所以加入这个变压器在我的POM只是工作,例如:

<project> 
    ... 
    <build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-shade-plugin</artifactId> 
     <version>2.0</version> 
     <executions> 
      <execution> 
      <phase>package</phase> 
      <goals> 
       <goal>shade</goal> 
      </goals> 
      <configuration> 
       <transformers> 
       <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> 
       </transformers> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
    ... 
</project> 

希望它能帮助!

相关问题