gpt4 book ai didi

java - payara 上的 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-12-02 03:41:04 26 4
gpt4 key购买 nike

最近我将我的开发从 Glassfish 4.1 迁移到 Payara-4.1.1.161.1。

今天我重新打开了几个月没有碰过的项目。当我尝试编译并运行该项目时,我在控制台日志中看到以下内容

        Severe:   WebModule[/EstoreAdmin]StandardWrapper.Throwable
java.lang.NoClassDefFoundError: org/eclipse/persistence/jpa/rs/exceptions/ClassNotFoundExceptionMapper
at com.app.service.ApplicationConfig.addRestResourceClasses(ApplicationConfig.java:27)
at com.app.service.ApplicationConfig.getClasses(ApplicationConfig.java:16)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig$3.run(ResourceConfig.java:1234)
at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.registerComponentsOf(ResourceConfig.java:1216)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1190)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1178)
at org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1174)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:345)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:390)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:172)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:364)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5732)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5977)
at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291)
at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:353)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:500)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:487)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.rs.exceptions.ClassNotFoundExceptionMapper
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1795)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
... 70 more

我花了很多时间试图找出发生了什么,将项目恢复到第一阶段,但仍然无法启动。

在绝望的举动中,我决定尝试在旧的 Glassfish 4.1 上发布这个项目(它仍然在我的硬盘上)。它开始没有任何问题。

我不知道问题的根源是什么。它与 ide 生成的部分有某种关系

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

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

/**
* Do not modify addRestResourceClasses() method.
* It is automatically populated with
* all resources defined in the project.
* If required, comment out calling this method in getClasses().
*/
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(org.eclipse.persistence.jpa.rs.exceptions.ClassNotFoundExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.ConversionExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.DatabaseExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.EntityExistsExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.EntityNotFoundExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.IOExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.IllegalAccessExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.IllegalArgumentExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.IllegalStateExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.InvocationTargetExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.JAXBExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.JPARSConfigurationExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.JPARSExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.MalformedURLExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.NamingExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.NoResultExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.NoSuchMethodExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.NonUniqueResultExceptionExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.OptimisticLockExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.PersistenceExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.PessimisticLockExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.QueryTimeoutExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.RollbackExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.TransactionRequiredExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.exceptions.UnsupportedMediaTypeExceptionMapper.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.EntityResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.PersistenceResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.PersistenceUnitResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.QueryResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.SingleResultQueryResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.unversioned.EntityResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.unversioned.PersistenceUnitResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.unversioned.QueryResource.class);
resources.add(org.eclipse.persistence.jpa.rs.resources.unversioned.SingleResultQueryResource.class);
}

我尝试切换 JDK。 JDK 1.8.77 和 1.8.91 的行为方式相同。我也尝试过预发布 payara 构建,同样的。

您能否给我一些建议,以便让 Payara 能够正常工作,以及如何跟踪错误。

编辑1

我相信这种行为在某种程度上与我的应用程序使用持久性模块中定义的 2 个连接这一事实有关。

如果我禁用线路

addRestResourceClasses(resources);

然后应用程序启动(但我的登录 Controller 不起作用,并且应用程序在尝试登录时出现异常)。

所以我再次启用了该行,但在登录 Controller 中我用 @Named 替换了 @ManagedBean 并稍微调整了 Controller 。此后我再也看不到错误了。我不确定为什么这会有所帮助。

编辑2

@Mike 披露了问题的根源。这是由于EclipseLink版本太旧造成的。我使用的是 2.5.2,正确的是 2.6.x

最佳答案

原来的错误是:

java.lang.NoClassDefFoundError: org/eclipse/persistence/jpa/rs/exceptions/ClassNotFoundExceptionMapper

原因是 Payara 使用的 Eclipselink 版本中已经重构了 ClassNotFoundExceptionMapper 类。

Glassfish 4.1使用 <2.5.2 (Payara 4.1.144 - 源自该版本的 GlassFish - 集成 2.5.2-RC1 ) which still contains that class

The class has been replaced by the AbstractExceptionMapper ,因此您需要重构您的应用程序以适应。

Payara 的最新版本使用 Eclipselink 版本 < 2.6版本是4.1.151现在已经有一年多了,所以建议的选择是更改代码而不是降级服务器。

关于java - payara 上的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36829650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com