无法启动WAR,嵌套异常是java.lang.NoClassDefFoundError:

时间:2014-04-17 10:27:03

标签: java eclipse spring maven rmi

我参与了一个使用以下相关技术的项目:

  • 的Maven
  • 弹簧
  • Java EE
  • Java RMI

在我的项目中,我有一个初始化类,我称之为ìnitService。该服务负责启动程序稍后将使用的主要结构。如果失败,程序将失败。

在此initService我正在尝试设置RMI服务器和客户端。到目前为止,这只相当于“helloWorld”。为了达到这个目的,我有一个接口和一个实现类:

public interface ICommunicator extends Remote{
    public boolean askNewVM() throws RemoteException;
    public boolean commitingSuicide() throws RemoteException;
}

public class RMICommunicator extends UnicastRemoteObject implements ICommunicator{

    private static final long serialVersionUID = 1L;

    public RMICommunicator() throws RemoteException {
        super();
    }

    @Override
    public boolean askNewVM()  throws RemoteException{
        return false;
    }

    @Override
    public boolean commitingSuicide()  throws RemoteException{
        return false;
    }

}

到目前为止一切顺利。然后我尝试使用war命令编译并生成mvn install文件,该命令运行没有问题。

然而,当我将生成的war文件部署到我的服务器并尝试使用Jetty 8.0启动它时,会出现问题。当我这样做时,由于以下错误,服务器无法启动:

[ERROR][context.ContextLoader]: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'initService': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: net/jnd/thesis/service/loadBalancer/RMICommunicator
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:39)
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:494)
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:141)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:145)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:56)
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:615)
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:540)
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:337)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:121)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:555)
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:230)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:81)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:96)
    at org.eclipse.jetty.server.Server.doStart(Server.java:282)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1274)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.jetty.start.Main.invokeMain(Main.java:473)
    at org.eclipse.jetty.start.Main.start(Main.java:615)
    at org.eclipse.jetty.start.Main.main(Main.java:96)
Caused by: java.lang.NoClassDefFoundError: net/jnd/thesis/service/loadBalancer/RMICommunicator
    at net.jnd.thesis.service.loadBalancer.VMManager.<init>(VMManager.java:83)
    at net.jnd.thesis.service.loadBalancer.VMManager.getInstance(VMManager.java:104)
    at net.jnd.thesis.service.loadBalancer.LoadBalancerService.start(LoadBalancerService.java:50)
    at net.jnd.thesis.service.InitializationService.start(InitializationService.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:346)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:299)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:132)
    ... 53 more
Caused by: java.lang.ClassNotFoundException: net.jnd.thesis.service.loadBalancer.RMICommunicator
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430)
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
    ... 64 more

我已经针对类似的问题研究了这个论坛,但没有成功。但是,我确实找到了关于这个问题的文章:

通过阅读它,我相信(虽然我可能错了),我的问题是第12步中描述的问题:

  

12)Java程序也可以   在链接发生时抛出java.lang.NoClassDefFoundError   在Java中加载类时。这种情况的一个例子是   从我们的静态初始化程序失败示例中删除User类   编译后,他们尝试运行该程序。这次你会的   直接得到java.lang.NoClassDefFoundError   java.lang.ExceptionInInitializerError和消息   NoClassDefFoundError也只是打印类的名称   测试/用户,即来自测试包的用户类。当心这个   仔细,因为这里没有User.class文件。

     

了解更多:   http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html#ixzz2z8cNlxZ9

我不相信我有任何罐子丢失,所以我认为这是一个猜测和其他任何一样好。我如何解决我的问题?

2 个答案:

答案 0 :(得分:0)

首先将* .war重命名为* .zip,看看编译的类是否存在。

否则,试试maven&gt;在IDE中更新,并确保将maven依赖项添加到类路径中。我有时会得到这些NoClassDev错误,并且在更新和类路径检查之后一切正常。

答案 1 :(得分:0)

问题是访问问题。事实证明,RMI的security.policy文件没有被正确读取(根本没有找到),因此我得到了一个ClassNotDefException而不是获得FileNotFoundException。

Permissions man ......他们真是太糟糕了。