Posted on 2006-03-09 10:08
么么茶 阅读(2952)
评论(2) 编辑 收藏 所属分类:
JAVA-WEB
近日因项目临近尾声,开始启动工程化的工作。但是才刚刚开始就遇到个不小的问题。我们的发布是将项目连同TOMCAT一起打包,而我们的项目中使用了RMI的通信,在启动项目时会建立一个RMI的server,这样问题就来了。当我们将项目安装在带有空格的目录中(如C:\Program Files\...)时,在启动TOMCAT时即会报错,报错的信息大致如下(其中隐去了部分公司相关代码):
java.io.IOException: Cannot bind to URL [jmx]: javax.naming.CommunicationException: Failed to retrieve stub from server 127.0.0.1:1099 [Root exception is java.net.MalformedURLException: no protocol: Files\]
at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:814)
at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:431)
at
javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
at org.apache.catalina.core.StandardHostDeployer.addChild(StandardHostDeployer.java:903)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
at org.apache.commons.digester.SetNextRule.end(SetNextRule.java:256)
at org.apache.commons.digester.Rule.end(Rule.java:276)
at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
at org.apache.catalina.util.CatalinaDigester.endElement(CatalinaDigester.java:76)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.commons.digester.Digester.parse(Digester.java:1567)
at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:488)
at org.apache.catalina.core.StandardHost.install(StandardHost.java:863)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:483)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:480)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
Caused by: javax.naming.CommunicationException: Failed to retrieve stub from server 127.0.0.1:1099 [Root exception is java.net.MalformedURLException: no protocol: Files\]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:161)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:871)
at org.jnp.interfaces.NamingContext.bind(NamingContext.java:377)
at org.jnp.interfaces.NamingContext.bind(NamingContext.java:370)
at javax.naming.InitialContext.bind(InitialContext.java:359)
at javax.management.remote.rmi.RMIConnectorServer.bind(RMIConnectorServer.java:635)
at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:427)
51 more
Caused by: java.net.MalformedURLException: no protocol: Files\
at java.net.URL.<init>(URL.java:567)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:747)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:147)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:151)
57 more 可以看到路径被从空格处截断了,致使RMI的server无法找到启动所需要的classpath。
通过查找相关的文档和资料,发现很多人都遇到过类似的问题,其中最有意义的信息是
There is a bug in the JDK which makes RMI fail if Tomcat is installed in directory containing spaces (e.g. C:\Program Files\Apache Group\Jakarta Tomcat 5.0). This bug won't be fixed, so you can only workaround it.
The installation should have checked the folder name for you and promted you to reinstall Tomcat. If you missed that or renamed the folder after you installed KIM, follow the seme advice now: reinstall Tomcat in a folder (using underscores instead of spaces for example) or just rename folders needed so that the full path contains no spaces. Then reinstall KIM too and point it to the new loacation when asked for Tomcat server, or to skip the new install just manually edit your start/stop Tomcat bat/sh files in %KIM_Platform_Home%/bin directory where this path is used.
For more details refer to:
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4543
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4496398
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4273532
按照上文的意思,这是一个由JDK引起的bug,而且今后也不会被修复。
但是我们的项目有两个版本,我所做的是WEB版的,而另外一个是独立运行版本。问题就在这儿,那个独立运行的版本安装在带有空格的目录中时依然可以正常工作,但是一旦放到TOMCAT中就不行了。通过反复查看上述报错信息中的各个类文件的报错位置,也未能找到确切的原因。但是因为这些类中有多处使用了ClassLoader,所以怀疑是因为放到TOMCAT中后缺省的ClassLoader和独立运行时不同,造成了在使用RMI相关的操作时出现了一些差别。