我正在尝试使用Restlet框架构建示例REST服务器。我已经从https://restlet.com/open-source/downloads/current/下载了restlet框架,并解压缩到了D:/restlet-jse-2.3.12 Windows文件夹中。 现在,我创建了一个没有原型的Eclipse Maven项目,并通过project->右键单击-> Java Build Path-> Libraries-> Add External Jars添加了restlet jars。 我已经在https://github.com/imaynotbereal/curly-sniffle/tree/master/restlet1
提交了代码在构建代码时,我遇到多个NoClassDefFoundError错误,如下所示:
Unable to register the helper org.restlet.ext.jdbc.JdbcClientHelper
java.lang.NoClassDefFoundError: org/apache/commons/dbcp/ConnectionFactory
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at org.restlet.engine.Engine.registerHelper(Engine.java:896)
at org.restlet.engine.Engine.registerHelpers(Engine.java:928)
at org.restlet.engine.Engine.registerHelpers(Engine.java:968)
at org.restlet.engine.Engine.discoverConnectors(Engine.java:654)
at org.restlet.engine.Engine.<init>(Engine.java:491)
at org.restlet.engine.Engine.register(Engine.java:382)
我意识到D:/restlet-jse-2.3.12/lib下有子文件夹,我不得不将其中的jar添加到Java Build Path-> Libraries(D:/ restlet-jse下的jars -2.3.12 / lib / org.apache.commons.dbcp_1.3文件夹以解决上述错误)
现在构建正常,所有NoClassDefFoundError错误均已解决,服务器开始在端口8081上侦听。但是,当我使用URL http://localhost:8081/product下面的资源请求资源时,出现ClassCastException错误:< / p>
Exception or error caught in server resource
java.lang.ClassCastException: Product cannot be cast to org.eclipse.emf.ecore.EObject
at org.restlet.ext.emf.EmfConverter.toRepresentation(EmfConverter.java:211)
at org.restlet.service.ConverterService.toRepresentation(ConverterService.java:342)
at org.restlet.resource.Resource.toRepresentation(Resource.java:945)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:515)
at org.restlet.resource.ServerResource.get(ServerResource.java:723)
at org.restlet.resource.ServerResource.doHandle(ServerResource.java:603)
at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:662)
at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:348)
at org.restlet.resource.ServerResource.handle(ServerResource.java:1020)
at org.restlet.resource.Finder.handle(Finder.java:236)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Router.doHandle(Router.java:422)
at org.restlet.routing.Router.handle(Router.java:641)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:140)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)
at org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:77)
at org.restlet.Application.handle(Application.java:385)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Router.doHandle(Router.java:422)
at org.restlet.routing.Router.handle(Router.java:641)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Router.doHandle(Router.java:422)
at org.restlet.routing.Router.handle(Router.java:641)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:140)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.routing.Filter.doHandle(Filter.java:150)
at org.restlet.routing.Filter.handle(Filter.java:197)
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)
at org.restlet.Component.handle(Component.java:408)
at org.restlet.Server.handle(Server.java:507)
at org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:63)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:143)
at org.restlet.ext.jetty.JettyServerHelper$WrappedServer.handle(JettyServerHelper.java:256)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Unknown Source)
2019-01-04 17:14:43 0:0:0:0:0:0:0:1 - 0:0:0:0:0:0:0:1 8081 GET /product - 500 486 0 84 http://localhost:8081 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 -
我检查了我的引用库,其中包含D:/restlet-jse-2.3.12/liborg.eclipse.emf_2.6文件夹下的jar,因此上述错误似乎不太可能是由于缺少jar。
我检查了Restlet文档中的示例,但不明白问题出在哪里。
我知道手动尝试将每个依赖的jar添加到Build References是不好的,但是目前我还不知道有更好的方法。如果有人可以指导我如何在这种情况下更有效地将jar添加到Java应用程序中,我将感到非常高兴。