我正在用Web逻辑部署耳文件。 该耳文件是RMI客户端,并使用一些3rd party jars。 这些第三方聚会罐需要以下属性:
System.setProperty("java.naming.provider.url", "localhost:1099");
System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
这些属性的问题是,这些混乱了weblogic管理控制台。 一旦触发了上述两个属性,就无法再访问控制台。
设置这些属性后尝试访问weblogic控制台时,出现以下异常:
<24/05/2019 5:23:34 PM EST> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: java.io.IOException: Unable to create InitialContext: javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at weblogic.management.remote.wlx.ClientProvider.findRMIServer(ClientProvider.java:126)
at weblogic.management.remote.wlx.ClientProvider.newJMXConnector(ClientProvider.java:103)
at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:369)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:267)
at com.bea.console.utils.MBeanUtils.lookupMBeanServerConnection(MBeanUtils.java:3658)
at com.bea.console.utils.MBeanUtils.getDomainRuntimeMBeanServerConnection(MBeanUtils.java:1840)
at com.bea.console.utils.MBeanUtils.getDomainRuntimeServiceMBean(MBeanUtils.java:1916)
at com.bea.console.utils.MBeanUtilsInitializer.initMBeanUtils(MBeanUtilsInitializer.java:70)
at com.bea.console.utils.MBeanUtilsInitializer.access$000(MBeanUtilsInitializer.java:20)
at com.bea.console.utils.MBeanUtilsInitializer$1.run(MBeanUtilsInitializer.java:49)
at weblogic.work.ContextWrap.run(ContextWrap.java:40)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:548)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at weblogic.management.remote.wlx.ClientProvider.findRMIServer(ClientProvider.java:124)
... 13 more
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:357)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:318)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:80)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:186)
at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:50)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
... 17 more
>
<24/05/2019 5:23:34 PM EST> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: Error when initilize JMX connection>
<24/05/2019 5:23:37 PM EST> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: java.io.IOException: Unable to create InitialContext: javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at weblogic.management.remote.wlx.ClientProvider.findRMIServer(ClientProvider.java:126)
at weblogic.management.remote.wlx.ClientProvider.newJMXConnector(ClientProvider.java:103)
at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:369)
因此清楚地在系统级别设置属性不是一个好主意,而且搞乱了网络逻辑。
由于这些属性已被第三方jar使用(我无法更改的代码),如何在不影响Web逻辑的情况下将这些属性提供给Jar?
基本上,应针对我的应用设置这些属性,而不会干扰Web逻辑。