invalid type code: 31和java虚拟机参数sun.lang.ClassLoader.allowArraySyntax

来源:互联网 发布:java io read 编辑:程序博客网 时间:2024/05/17 07:56

Unable to connect to 't3://localhost:7001': invalid type code: 31.

今天在使用weblogic 命令行工具部署EJB的时候,出现如下的问题:
C:/Documents and Settings/hg06574>java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

C:/Documents and Settings/hg06574>
C:/Documents and Settings/hg06574>java -classpath C:/wls/weblogic.jar weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
weblogic.Deployer invoked with options:  -adminurl t3://localhost:7001 -user weblogic -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
Unable to connect to 't3://localhost:7001': invalid type code: 31. Ensure the url represents a running admin server and that the credentials are correct. If using http protocol, tunneling must be enabled on the admin server.

其中:
weblogic9.2 使用jdk1.5.0_10
ejbStudy.jar使用jdk1.5.0_10编译,
上面命令行使用的是jdk1.6.0_05,出现上面的错误是因为虚拟机参数sun.lang.ClassLoader.allowArraySyntax造成的。
在jdk1.5中,这个参数默认值是true,而在jdk1.6中这个参数的默认值是false。如果要使用jdk1.6去执行上面的部署命令,需要修改虚拟机这个参数的值为true,如下:
C:/Documents and Settings/hg06574>java -Dsun.lang.ClassLoader.allowArraySyntax=true -classpath C:/wls/weblogic.jar weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
weblogic.Deployer invoked with options:  -adminurl t3://localhost:7001 -user weblogic -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
<Jan 5, 2011 5:02:14 PM CST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, ejbStudy.jar [archive: C:/011_temp/ejbStudy.jar], to AdminServer .>
Task 5 initiated: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Task 5 completed: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Target state: deploy completed on Server AdminServer

这样就没有问题了。
如果使用jdk1.5去执行上面的部署命令,就不用修改这个参数了,因为默认值就是true。

C:/DialogDesigner>set JAVA_HOME=C:/java/jdk150_10
C:/DialogDesigner>set classpath=.;C:/java/jdk150_10/lib/tools.jar;C:/java/jdk150_10/lib/dt.jar;C:/wls/api.jar;C:/wls/wls-api.jar
C:/DialogDesigner>set path=C:/java/jdk150_10/bin;
C:/IVR_CCJ/ejbStudy/build>java -classpath C:/wls/weblogic.jar weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
weblogic.Deployer invoked with options:  -adminurl t3://localhost:7001 -user weblogic -targets AdminServer -deploy C:/IVR_CCJ/ejbStudy/archiveFiles/ejbStudy.jar
<Jan 5, 2011 5:55:06 PM CST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, ejbStudy.jar [archive: C:/011_temp/ejbStudy.jar], to AdminServer .>
Task 5 initiated: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Task 5 completed: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Target state: deploy completed on Server AdminServer


导致这个问题的根本原因就是虚拟机的参数sun.lang.ClassLoader.allowArraySyntax,如上所述在jdk1.5中,这个参数默认值是true,而在jdk1.6中这个参数的默认值是false。
那么这个参数的作用是什么?
搜索jdk1.6的源代码,可以发现,在java.lang.System类中有如下的描述:
// Set a boolean to determine whether ClassLoader.loadClass accepts
// array syntax.  This value is controlled by the system property
// "sun.lang.ClassLoader.allowArraySyntax".  This method acts as
// an initializer only if it is called before sun.misc.VM.booted().
sun.misc.VM.allowArraySyntax();

由于这个参数在jdk1.5和jdk1.6中的默认值不同,所以在用jdk1.6去加载jdk1.5编译的类时,就可能出现问题。
上面的问题就是因为使用jdk1.6去加载C:/wls/weblogic.jar使引起的,weblogic9.2里的weblogic.jar是jdk1.5编译的(weblogic9.2里面内置的jdk是1.5的,由此推断)。

使用jdk1.6去加载weblogic10的weblogic.jar一样会引起这个错误:
javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException
        at weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl.<init>(WebLogicDeploymentManagerImpl.java:121)
        at weblogic.deploy.api.spi.factories.internal.DeploymentFactoryImpl.getDeploymentManager(DeploymentFactoryImpl.java:84)
        at weblogic.deploy.api.tools.SessionHelper.getDeploymentManager(SessionHelper.java:432)
        at weblogic.deploy.api.tools.deployer.Jsr88Operation.connect(Jsr88Operation.java:304)
        at weblogic.deploy.api.tools.deployer.Deployer.perform(Deployer.java:137)
        at weblogic.deploy.api.tools.deployer.Deployer.runBody(Deployer.java:88)
        at weblogic.utils.compiler.Tool.run(Tool.java:158)
        at weblogic.utils.compiler.Tool.run(Tool.java:115)
        at weblogic.Deployer.run(Deployer.java:70)
        at weblogic.Deployer.main(Deployer.java:54)
Caused by: weblogic.deploy.api.spi.exceptions.ServerConnectionException
        at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.init(ServerConnectionImpl.java:143)
        at weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl.getNewConnection(WebLogicDeploymentManagerImpl.java:148)
        at weblogic.deploy.api.spi.deploy.WebLogicDeploymentManagerImpl.<init>(WebLogicDeploymentManagerImpl.java:118)
        ... 9 more
Caused by: javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: failed to unmarshal class weblogic.security.acl.internal.Authenticate
dUser; nested exception is:
        java.io.StreamCorruptedException: invalid type code: 31]
        at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:74)
        at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:32)
        at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773)
        at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialContextFactoryDelegate.java:673)
        at weblogic.jndi.WLInitialContextFactoryDelegate.newContext(WLInitialContextFactoryDelegate.java:466)
        at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:373)
        at weblogic.jndi.Environment.getContext(Environment.java:307)
        at weblogic.jndi.Environment.getContext(Environment.java:277)
        at weblogic.jndi.Environment.createInitialContext(Environment.java:200)
        at weblogic.jndi.Environment.getInitialContext(Environment.java:184)
        at weblogic.jndi.Environment.getInitialContext(Environment.java:162)
        at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.getContext(ServerConnectionImpl.java:330)
        at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.getEnvironment(ServerConnectionImpl.java:302)
        at weblogic.deploy.api.spi.deploy.internal.ServerConnectionImpl.init(ServerConnectionImpl.java:141)
        ... 11 more
Caused by: java.rmi.UnmarshalException: failed to unmarshal class weblogic.security.acl.internal.AuthenticatedUser; nested exception is:
        java.io.StreamCorruptedException: invalid type code: 31
        at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:229)
        at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:224)
        at weblogic.common.internal.RMIBootServiceImpl_1001_WLStub.authenticate(Unknown Source)
        at weblogic.security.acl.internal.Security$1.run(Security.java:185)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
        at weblogic.security.service.SecurityManager.runAs(Unknown Source)
        at weblogic.security.acl.internal.Security.authenticate(Security.java:181)
        at weblogic.jndi.WLInitialContextFactoryDelegate.authenticateRemotely(WLInitialContextFactoryDelegate.java:734)
        at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialContextFactoryDelegate.java:667)
        ... 21 more
Caused by: java.io.StreamCorruptedException: invalid type code: 31
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1356)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:195)
        at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:565)
        at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:191)
        at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62)
        at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:227)
        ... 29 more
Unable to connect to 't3://localhost:7001': invalid type code: 31. Ensure the url represents a running admin server and that the credentials are correct. If using h
ttp protocol, tunneling must be enabled on the admin server.


实验中还有如下的情况:
weblogic9.2 使用 1.5.0_10
ejbStudy.jar使用jdk1.6编译,
使用jdk1.6部署,并加上参数-Dsun.lang.ClassLoader.allowArraySyntax=true,也是无法部署上的。

C:/Documents and Settings/hg06574>java -Dsun.lang.ClassLoader.allowArraySyntax=true -classpath C:/wls/weblogic.jar weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogi
c -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
weblogic.Deployer invoked with options:  -adminurl t3://localhost:7001 -user weblogic -targets AdminServer -deploy C:/011_temp/ejbStudy.jar
<Jan 5, 2011 5:39:22 PM CST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, ejbStudy.jar [archive: C:/011_temp/ejbStudy.jar], to AdminServer .>
Task 6 initiated: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Task 6 failed: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Target state: deploy failed on Server AdminServer
Unable to load a class specified in your ejb-jar.xml: Class bytes found but defineClass()failed for: 'haiyang.ejbStudy.testSessionBean.statefulSessionBean.CountBean'

使用jdk1.5部署,错误一样,

C:/IVR_CCJ/ejbStudy/build>java -classpath C:/wls/weblogic.jar weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -targets AdminServer -deploy C:/IVR_CCJ/ejbStudy/ar
chiveFiles/ejbStudy.jar
weblogic.Deployer invoked with options:  -adminurl t3://localhost:7001 -user weblogic -targets AdminServer -deploy C:/IVR_CCJ/ejbStudy/archiveFiles/ejbStudy.jar
<Jan 5, 2011 5:42:46 PM CST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, ejbStudy.jar [archive: C:/IVR_CCJ/ejbStudy/archiveFiles/ejbStudy.jar], to Admi
nServer .>
Task 7 initiated: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Task 7 failed: [Deployer:149026]deploy application ejbStudy.jar on AdminServer.
Target state: deploy failed on Server AdminServer
Unable to load a class specified in your ejb-jar.xml: Class bytes found but defineClass()failed for: 'haiyang.ejbStudy.testSessionBean.statefulSessionBean.CountBean'

这个错误是因为ejbStudy.jar使用jdk1.6编译的,而weblogic9.2是使用的jdk 1.5.0_10,所以部署不上。
starting weblogic with Java version:
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) Client VM (build 1.5.0_10-b03, mixed mode)

 

 

下面是从网上搜到的由于这个参数导致的其他可能的错误:

ClassLoader.loadClass() throws java.lang.ClassNotFoundException: [Ljava.lang.String
或者类似如下错误
java.lang.IllegalStateException: Class not found: [Ljava.lang.String

如果在使用jdk1.6的时候出现类似数组有关的错误,可以先看看是否是因为这个参数的问题,当然解决方法就是修改虚拟机的这个参数,运行java的时候加上-Dsun.lang.ClassLoader.allowArraySyntax=true

在sun的网站上也有这个问题的讨论。http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6812887

在其它应用里也有这个参数的设置说明:
https://issues.jboss.org/browse/JBPAPP-2294


http://docs.jboss.com/seam/2.1.1.GA/reference/en-US/html/configuration.html

If you are using Sun JDK 6, you need to set the Java option sun.lang.ClassLoader.allowArraySyntax to true in the JAVA_OPTS environment variable used by the Catalina startup script (catalina.bat on Windows or catalina.sh on Unix).

Open the script appropriate for your operating system in a text editor. Add a new line immediately below the comments at the top of the file where you will define the JAVA_OPTS environment variable. On Windows, use the following syntax:

set JAVA_OPTS=%JAVA_OPTS% -Dsun.lang.ClassLoader.allowArraySyntax=trueOn Unix, use this syntax instead:

JAVA_OPTS="$JAVA_OPTS -Dsun.lang.ClassLoader.allowArraySyntax=true"For more configuration options, please see the Embedded JBoss Tomcat integration wiki entry.


另外,JBOSS 5启动报错
如果下载JBOSS 5,安装的JDK的版本是6.0,启动时JBOSS会报错,这是因为JDK5和JDK6中加入了一个"sun.lang.ClassLoader.allowArraySyntax"选项值,这个值默认是true
而,JDK6却将其改为flase,所以启动JOBSS5会报错,如果是将JBOSS服务器解压到windows下使用,则只需修改run.bat文件,找到"set JAVA_OPTS=%JAVA_OPTS%-Dprograme.name=%PROGNAME%"这一行,
将这一行改为"set JAVA_OPTS=%JAVA_-OPTS%Dprograme.name=%PROGNAME%Dsun.lang.ClassLoader.allowArraySyntax=true",这样JBOSS5就能正常运行了

 

 

原创粉丝点击