开发者

Java web service tomcat not able to find a shared lib

I'm using eclipse and I have a java web service (rest jax-rs) I also have another java project that contains a class Employee

In the web service project and I have gone to Java Build Path/Projects and added the project containing the Employee class.

No compilation erros.

In the web service I have a method like this:

    @GET
    @Path("{extra}")
    public Employee person(@PathParam("extra") String cus) {

        Employee p = new Employee();
        p.setName(cus);
        retur开发者_运维技巧n p;

    }

When Run (it seems to starts tomcat server) I get the following error

java.lang.NoClassDefFoundError: shared/Employee
    java.lang.Class.getDeclaredMethods0(Native Method)
    java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    java.lang.Class.privateGetPublicMethods(Unknown Source)
    java.lang.Class.getMethods(Unknown Source)
    com.sun.jersey.core.reflection.MethodList.getMethods(MethodList.java:77)
    com.sun.jersey.core.reflection.MethodList.<init>(MethodList.java:64)
    com.sun.jersey.core.reflection.MethodList.<init>(MethodList.java:60)
    com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:116)
    com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:743)
    com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1518)
    com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1295)
    com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:167)
    com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:773)
    com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:769)
    com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:769)
    com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:764)
    com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
    com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
    com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)

Obviously everything works when the Employee class is defined in the same project.

What am I missing?


That Java project needs to end up as JAR in /WEB-INF/lib folder of the deploy in order to be available in the webapp's runtime classpath. Only adding the Java project as project to the build path of the web project is not sufficient. This only covers the web project's compiletime classpath, not the webapp's runtime classpath.

You need to add the Java project in Deployment Assembly of the web project to get it to end up as JAR in /WEB-INF/lib.

Java web service tomcat not able to find a shared lib

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜