java.lang.NoClassDefFoundError: scala/collection/convert/DecorateAsScala 但 pom.xml 中的 scala-library
Posted
技术标签:
【中文标题】java.lang.NoClassDefFoundError: scala/collection/convert/DecorateAsScala 但 pom.xml 中的 scala-library 使用 swagger 和 JBoss servlet【英文标题】:java.lang.NoClassDefFoundError: scala/collection/convert/DecorateAsScala but scala-library in pom.xml to use swagger with JBoss servlet 【发布时间】:2021-12-18 20:13:34 【问题描述】:我正在将我的第一个 Swagger 描述添加到一个使用 RestEasy 构建并使用当前版本的 JBoss EAP 部署到服务器的简单、可工作的 servlet。从示例 pom.xml 中添加许多依赖项后,包括
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.7</version>
</dependency>
我得到以下堆栈跟踪。请注意,我也尝试过其他版本的 scala,结果相同
1:17:18,353 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 100) MSC000001: Failed to start service jboss.deployment.unit."PamHelper.war".undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit."PamHelper.war".undertow-deployment: java.lang.NoClassDefFoundError: scala/collection/convert/DecorateAsScala
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads@2.3.3.Final-redhat-00001//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads@2.3.3.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads@2.3.3.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads@2.3.3.Final-redhat-00001//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.jboss.threads@2.3.3.Final-redhat-00001//org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.lang.NoClassDefFoundError: scala/collection/convert/DecorateAsScala
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3191)
at java.base/java.lang.Class.getMethods(Class.java:1904)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.spi.metadata.ResourceBuilder.fromAnnotations(ResourceBuilder.java:861)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.spi.metadata.ResourceBuilder.getRootResourceFromAnnotations(ResourceBuilder.java:830)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.<init>(POJOResourceFactory.java:38)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:79)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:485)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.spi.ResteasyDeployment.startInternal(ResteasyDeployment.java:282)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:89)
at org.jboss.resteasy.resteasy-jaxrs@3.9.3.SP1-redhat-00001//org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:25)
at io.undertow.servlet@2.0.28.SP1-redhat-00001//io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)
at io.undertow.servlet@2.0.28.SP1-redhat-00001//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:217)
at io.undertow.servlet@2.0.28.SP1-redhat-00001//io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:186)
at io.undertow.servlet@2.0.28.SP1-redhat-00001//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
at io.undertow.servlet@2.0.28.SP1-redhat-00001//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1504)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1504)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1504)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1504)
at io.undertow.servlet@2.0.28.SP1-redhat-00001//io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:252)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:96)
at org.wildfly.extension.undertow@7.3.0.GA-redhat-00004//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:78)
... 8 more
Caused by: java.lang.ClassNotFoundException: scala.collection.convert.DecorateAsScala from [Module "deployment.PamHelper.war" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
... 33 more
我从讨论在 JBoss 下使用 Swagger 和 RestEasy 的帖子中获取我的依赖项,但这似乎仍然是一个依赖项问题。我没有看到另一个 scala 依赖项 - DecorateAsScala 还需要什么其他依赖项?
【问题讨论】:
【参考方案1】:scala.collection.convert.DecorateAsScala
在 Scala 2.13.7 中不存在。您可能想尝试 2.12.15。如果遇到类似的错误,甚至是 2.11.12。
我想知道您是否真的需要 Scala 依赖项。你提到的所有东西似乎都不需要 Scala。除非您想将 Swagger 用于 Scala,但我想情况并非如此。无论哪种方式,如果它是一个传递依赖,如果你自己没有声明它,Maven 应该会自动下载正确的版本。
【讨论】:
以上是关于java.lang.NoClassDefFoundError: scala/collection/convert/DecorateAsScala 但 pom.xml 中的 scala-library 的主要内容,如果未能解决你的问题,请参考以下文章