我在Jersey
上有一个Spring
/ Project A
项目(com.project.a
:Eclipse
),该项目依赖于另一个项目(Project B
:{{ 1}})。
com.project.b
在本地Eclipse
服务器上构建和运行应用程序之前,不会在项目上显示任何错误。
它抛出此错误:
Tomcat
SEVERE: StandardWrapper.Throwable
MultiException stack 1 of 1
java.lang.NoClassDefFoundError: com/project/b/SomeClassToRegister
at com.project.a.CustomApplication.<init>(CustomApplication.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1129)
at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009)
at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:905)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:997)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:989)
at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:340)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:319)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:336)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1228)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5449)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5747)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.project.b.SomeClassToRegister
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1955)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1798)
... 28 more
Jul 09, 2019 5:52:13 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [com.project.a.CustomApplication] in web application [/someApplication] threw load() exception
java.lang.ClassNotFoundException: com.project.b.SomeClassToRegister
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1955)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1798)
at com.project.a.CustomApplication.<init>(CustomApplication.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1129)
at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009)
at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:905)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:997)
at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:989)
at org.glassfish.jersey.server.ApplicationHandler.createApplication(ApplicationHandler.java:340)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:319)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:336)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1228)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1066)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5449)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5747)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1707)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1697)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
扩展了CustomApplication
并尝试如下注册该类:
org.glassfish.jersey.server.ResourceConfig
有趣的是,public class CustomApplication extends ResourceConfig {
public CustomApplication() {
// Specify packages of java code.
packages("com.project.a");
packages("com.project.b"); //>>> Line 30
register(com.project.b.SomeClassToRegister.class); //>>> Line 31
}
}
毫无问题地调用com.project.b的主包,但是代码在Line 30
上崩溃了。 line 31
存在于依赖项com.project.b.SomeClassToRegister
上。
显示错误后,将正常显示服务器的com.project.b
welcome-file
页,但是每个端点在访问时都会引发相同的jsp
错误。
NoClassDefFoundError
的构建路径具有Project A
作为列出的依赖项,并且Project B
也被列为Project B
的{{1}}包装的一部分。
我目前正在使用以下资源配置在本地Tomcat服务器上运行它。我试图删除具有相同结果的Project B的重复外观。
https://jsfiddle.net/jqe5gfru/4/
我是否缺少有关将两个项目链接在一起的任何信息,这可能是导致错误的原因?
答案 0 :(得分:0)
在对两个项目的配置进行了很多摆弄之后,对我有用的是: