使用Java 9运行应用程序,模块java.base不会“打开java.io”

ar5n3qh5  于 2023-05-12  发布在  Java
关注(0)|答案(3)|浏览(211)

我尝试用Java 9运行我的应用程序(前端用Java Swing开发,服务器用部署在Wildfly 8上的EJB开发)。当客户端尝试建立EJB连接时,出现以下异常:

09:53:42,358 INFO  [xnio] XNIO version 3.2.0.Final
09:53:42,465 INFO  [nio] XNIO NIO Implementation Version 3.2.0.Final
09:53:42,507 DEBUG [nio] Started channel thread 'Remoting "config-based-naming-client-endpoint" I/O-1', selector sun.nio.ch.WindowsSelectorImpl@4b4a5caf
RmiServiceFactpry ExceptionInInitializerError
java.lang.ExceptionInInitializerError
    at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.<init>(RemotingConnectionEJBReceiver.java:148)
    at org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver.<init>(RemotingConnectionEJBReceiver.java:106)
    at org.jboss.ejb.client.EJBClientContext.registerConnection(EJBClientContext.java:465)
    at org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler.associate(RemoteNamingStoreEJBClientHandler.java:78)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.<init>(RemoteNamingStoreV1.java:71)
    at org.jboss.naming.remote.protocol.v1.VersionOne.getRemoteNamingStore(VersionOne.java:50)
    at org.jboss.naming.remote.protocol.Versions.getRemoteNamingStore(Versions.java:55)
    at org.jboss.naming.remote.client.RemoteContextFactory.createVersionedStore(RemoteContextFactory.java:73)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:202)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:149)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:130)
    at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79)
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83)
    at java.naming/javax.naming.InitialContext.lookup(Unknown Source)
    at com.dataloy.client.core.RmiServiceFactory.createRemote(RmiServiceFactory.java:105)
    at com.dataloy.client.core.RmiServiceFactory.getServiceImpl(RmiServiceFactory.java:96)
    at com.dataloy.core.AbstractServiceFactory.getService(AbstractServiceFactory.java:58)
    at com.dataloy.DataloyEngine.getService(DataloyEngine.java:198)
    at com.dataloy.DataloyEngine.login(DataloyEngine.java:548)
    at com.dataloy.client.login.LoginPanel.doLogin(LoginPanel.java:511)
    at com.dataloy.client.login.LoginPanel.access$500(LoginPanel.java:56)
    at com.dataloy.client.login.LoginPanel$5.run(LoginPanel.java:452)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make java.io.OptionalDataException(boolean) accessible: module java.base does not "opens java.io" to unnamed module @312002a1
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(Unknown Source)
    at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Unknown Source)
    at java.base/java.lang.reflect.Constructor.setAccessible(Unknown Source)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction$1.run(Marshalling.java:385)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction$1.run(Marshalling.java:381)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction.<init>(Marshalling.java:381)
    at org.jboss.marshalling.Marshalling$OptionalDataExceptionCreateAction.<init>(Marshalling.java:376)
    at org.jboss.marshalling.Marshalling.<clinit>(Marshalling.java:374)
    ... 23 more

我看到Java 9中引入的新模块管理存在一些问题,但我不明白应该怎么做。
问候,安德里亚

j0pj023g

j0pj023g1#

根据this answer,您需要将--add-opens java.base/java.io=ALL-UNNAMED添加到启动应用程序的java命令中。

x4shl7ld

x4shl7ld2#

添加以下JVM参数:

--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

不再达到上述异常,之前失败,但出现以下异常:

java.lang.ClassNotFoundException: com.dataloy.client.Main
    at jdk.deploy@9-ea/com.sun.deploy.security.DeployURLClassLoader.findClass(Unknown Source)
    at jdk.javaws@9-ea/com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at jdk.javaws@9-ea/com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at jdk.javaws@9-ea/com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at jdk.javaws@9-ea/com.sun.javaws.Launcher.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)

我需要使更多的模块可见,但我很难理解是哪一个。
安德里亚

2cmtqfgy

2cmtqfgy3#

我以前遇到过同样的问题,我解决了它,你可以检查这个答案:https://stackoverflow.com/a/76207178/15721679

相关问题