Glassfish 3.1.2.2上的java.lang.NoClassDefFoundError

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Glassfish 3.1.2.2上的java.lang.NoClassDefFoundError相关的知识,希望对你有一定的参考价值。

试图将我们的项目降级为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类。任何的想法?

谢谢你的帮助

答案

由于某些原因,您的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的更多详细信息

以上是关于Glassfish 3.1.2.2上的java.lang.NoClassDefFoundError的主要内容,如果未能解决你的问题,请参考以下文章

glassfish3新建domain

GlassFish服务器安装可执行文件无法打开

Glassfish 管理控制台可以拥有多个具有特定权限的用户吗?

NetBeans 上的 GlassFish 部署错误

使用Windows 10在Eclipse ee上的Glassfish 4的位置

无法使用Glassfish3上的JDBC连接到数据库