Glassfish 3.1.2.2上的java.lang.NoClassDefFoundError

时间:2017-12-15 12:10:09

标签: java netbeans glassfish glassfish-3

尝试将我们的项目降级到Glassfish 3.1.2.2上的Java 1.6。最近我们有一个在Glassfish 4.1上运行并使用Java 1.8构建的项目。不幸的是,我们的网站在Glassfish 3.1.2.2上使用java 1.6。但是我们必须改变我们的构建版本。我们的Java Web Service在Glassfish 4.1上运行良好,但在3.1.2.2上获得此异常。

Info: Initiating Jersey application, version 'Jersey: 1.11.1 03/31/2012 06:49 PM'
Severe: WebModule[/WS_ivi]StandardWrapper.Throwable
java.lang.NoClassDefFoundError: com/yai/ivi/rs/IVIAPIS
    at com.yai.ivi.app.AppConfig.addRestResourceClasses(AppConfig.java:21)
    at com.yai.ivi.app.AppConfig.getClasses(AppConfig.java:16)
    at com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder.<init>(DeferredResourceConfig.java:90)
    at com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder.<init>(DeferredResourceConfig.java:78)
    at com.sun.jersey.server.impl.application.DeferredResourceConfig.getApplication(DeferredResourceConfig.java:75)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1140)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1453)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1093)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:189)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)

Warning: StandardWrapperValve[com.yai.ivi.app.AppConfig]: PWC1382: Allocate exception for servlet com.yai.ivi.app.AppConfig
java.lang.NoClassDefFoundError: com/yai/ivi/rs/IVIAPIS
    at com.yai.ivi.app.AppConfig.addRestResourceClasses(AppConfig.java:21)
    at com.yai.ivi.app.AppConfig.getClasses(AppConfig.java:16)
    at com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder.<init>(DeferredResourceConfig.java:90)
    at com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder.<init>(DeferredResourceConfig.java:78)
    at com.sun.jersey.server.impl.application.DeferredResourceConfig.getApplication(DeferredResourceConfig.java:75)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1140)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
    at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1453)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1093)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:189)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)

从这个日志中读取后,这告诉我们没有定义类,但我们的Netbeans编译得很好。这是我们的AppConfig

@javax.ws.rs.ApplicationPath("webresources")
public class AppConfig extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
        addRestResourceClasses(resources);
        return resources;
    }

    private void addRestResourceClasses(Set<Class<?>> resources) {
        resources.add(com.yai.ivi.rs.IVIAPIS.class);
    }
}

这是我们的休息申请

@GET
@Path("/sampler")
@Produces(MediaType.APPLICATION_JSON)
public String getSampleData() throws Exception {   
    JSONObject outputJsonObj = new JSONObject();
    outputJsonObj.put("output", "Hello, i'm ivi!");         
    return outputJsonObj.toString();
}

以上异常将仅显示测试人员的json文件。

{"output":"Hello, i'm ivi!"}

我已检查过我们的软件包中是否存在IVIAPIS类。 有什么想法吗?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

由于某些原因,您的 AppConfig servlet找不到com.yai.ivi.rs.IVIAPIS类。缩小问题,我会考虑采取以下步骤:

  • 检查生成的.war文件是否包含 com.yai.ivi.rs.IVIAPIS (通常位于Netbeans项目的 dist 文件夹中)
  • 检查.war文件中 com.yai.ivi.rs.IVIAPIS 的位置,如果你在战争中找到它,那么它应该在WEB_INF / lib目录中,就我而言知道。

您可以查看此答案,了解 NoClassDefFoundError 的更多详细信息 https://stackoverflow.com/a/5756989/4424646