我尝试动态地将weblogic服务器(12.1.3)的weblogic.jar加载到类路径中,例如在运行时通过UrlClassloader。然后我想使用这个类加载器通过反射加载和启动emebedded weblogic服务器(原因是我们构建了自己的自定义测试运行器):
File file = new File("D:/Oracle/wls12130/wlserver/server/lib/weblogic.jar");
URL[] urls = new URL[]{file.toURI().toURL()};
URLClassLoader urlClassLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());
Class<?> factoryClass = urlClassLoader.loadClass("weblogic.server.embed.EmbeddedServerFactory");
Class<?> serverClass = urlClassLoader.loadClass("weblogic.server.embed.EmbeddedServer");
Object factoryObject = factoryClass.newInstance();
Method factoryMethod = factoryClass.getDeclaredMethod("getEmbeddedServer");
Method serverMethod = serverClass.getDeclaredMethod("start");
Object server = factoryMethod.invoke(factoryObject);
serverMethod.invoke(server);
仅当我手动将weblogic.jar(通常位于weblogic服务器的server / lib&#39;目录中)添加到IDE(eclipse或intellij)中的类路径时,代码才有效。但是,它应该通过urlclassloader加载类而不将weblogic.jar作为IDE中的外部库加载,这给了我以下异常:
weblogic.server.embed.EmbeddedServerException: Error creating default domain
at weblogic.server.embed.internal.DomainConfig.createConfig(DomainConfig.java:235)
at weblogic.server.embed.internal.DomainConfig.getDefaultDomain(DomainConfig.java:143)
at weblogic.server.embed.internal.DomainConfig.ensureInitialized(DomainConfig.java:66)
at weblogic.server.embed.internal.EmbeddedServerImpl.ensureStarted(EmbeddedServerImpl.java:213)
at weblogic.server.embed.internal.EmbeddedServerImpl.start(EmbeddedServerImpl.java:111)
... 10 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at weblogic.management.internal.CIEDomainGenerator.generateDefaultDomain(CIEDomainGenerator.java:62)
at weblogic.server.embed.internal.EmbeddedServerProvider.createDefaultDomain(EmbeddedServerProvider.java:142)
at weblogic.server.embed.internal.DomainConfig.createConfig(DomainConfig.java:233)
... 14 more
Caused by: com.oracle.cie.domain.DomainConfigException: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
at com.oracle.cie.domain.DomainInfoHelper.createDefaultDomain(DomainInfoHelper.java:824)
at com.oracle.cie.domain.DomainInfoHelper.createDefaultDomain(DomainInfoHelper.java:705)
... 21 more
我在这里做错了什么?