我使用Swarm 2017.3.X和2017.5.0。当我在新包中添加一个新类时,我在运行时得到了java.lang.ClassNotFoundException引起的NoClassDefFoundError。为什么呢?
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError
...
Caused by: java.lang.NoClassDefFoundError: com/example/myapp/newpackage/NewClass
at com.example.myapp.MyBean.getSomething(MyBean.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
... 45 more
Caused by: java.lang.ClassNotFoundException: com.example.myapp.newpackage.NewClass from [Module "deployment.198f19d8-46c4-4bf5-96fd-101dc0f57abd.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
... 57 more
Swarm查找 com.example.myapp (Main.java所在的)中的所有Java类,但不查找 com.example.myapp.newpackage 中的类(其中) NewClass.java是)。
答案 0 :(得分:0)
在Swarm中,您必须在Main类中添加每个包:
deployment.addPackage(Main.class.getPackage());
deployment.addPackage(NewClass.class.getPackage()); //new
deployment.addAllDependencies();
然后它有效!