简体   繁体   English

在Tomcat 7中运行RMI客户端得到ClassNotFoundException

[英]Running RMI client in Tomcat 7 got ClassNotFoundException

I am having some difficulties with RMI and Tomcat. 我在使用RMI和Tomcat时遇到一些困难。 This is the big picture of this project I am working on: the RMI client is called by a Java servlet that runs in Tomcat, the servlet accept user input and pass the parameters to the RMI client. 这是我正在从事的项目的总体情况:RMI客户端由运行在Tomcat中的Java servlet调用,该servlet接受用户输入并将参数传递给RMI客户端。 Then the RMI client then calls the RMI server to run the heavy compuation part. 然后,RMI客户端随后调用RMI服务器来运行繁重的计算部分。 The problem is that although everything works fine without hosting the RMI client in the Tomcat server, it doesn't run once I put it in Tomcat. 问题是,尽管在不将RMI客户端托管在Tomcat服务器中的情况下一切正常,但是一旦将其放置在Tomcat中,它就无法运行。 Here are some configurations: I DID NOT set up the security manager in the code, I assume that Tomcat will use its own. 这里是一些配置:我没有在代码中设置安全管理器,我假设Tomcat将使用它自己的。

    //if (System.getSecurityManager() == null) {
    //    System.setSecurityManager(new SecurityManager());
    //}

I also set the permission as following: 我还将权限设置如下:

$CATALINA_HOME/conf/catalina.policy $ CATALINA_HOME / conf / catalina.policy

grant codeBase "file:${catalina.home}/webapps/MyAPP/WEB-INF/classes/-" { 
    permission java.security.AllPermission "", ""; }; 
grant codeBase "file:${catalina.home}/webapps/MyAPP/WEB-INF/lib/-" { 
    permission java.security.AllPermission "", ""; 
}; 
grant codeBase "file:${catalina.home}/webapps/MyAPP/WEB-INF/lib/some-common-3.0.jar" { 
    permission java.io.FilePermission "*", "read, write"; 
};

Other than these two configurations, I didn't set any java.rmi.server.codebase or java.security.policy. 除了这两种配置,我没有设置任何java.rmi.server.codebase或java.security.policy。

I got the following error by submitting the code from RMI client to RMI server: 通过将代码从RMI客户端提交到RMI服务器,出现以下错误:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: mypackage.SomeClass
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:334)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at com.sun.proxy.$Proxy19.executeTask(Unknown Source)
at cluster.server.centralservice.CentralManagementServer.submitJob(CentralManagementServer.java:232)
at cluster.server.centralservice.JobSubmitter.runJob(JobSubmitter.java:226)
at cluster.server.centralservice.JobSubmitter.doPost(JobSubmitter.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: mypackage.SomeClass

I have been stuck here for a few days. 我被困在这里几天了。 Most examples I searched online is outdated and do not cover the RMI with Tomcat set up. 我在网上搜索的大多数示例已经过时,并且没有涵盖Tomcat设置的RMI。 Can anybody help? 有人可以帮忙吗? Many thanks. 非常感谢。

as the exception says 作为例外

java.lang.ClassNotFoundException: mypackage.SomeClass

this happens coz RMI is using a seperate class loader which isn't able to see SomeClass . 发生这种情况是因为RMI使用的是无法看到SomeClass的单独的类加载器。

Add <Loader delegate="true"/> into context.xml file (to Context element) in tomcat/conf directory. <Loader delegate="true"/>到tomcat / conf目录中的context.xml文件中(到Context元素中)。

This change fixed a similar issue I faced (not particularly with RMI) but worth a try. 此更改解决了我遇到的类似问题(特别是对于RMI),但是值得一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM