這一個開始驅動我完全堅果...SerialinitContextFactory在glassfish命名中找不到
我想創建一個使用Maven的Glassfish客戶端應用程序。
對於這一點,我已經添加了requried GF-客戶依賴性:
<dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
然後,想聯繫我的GlassFish服務器,在同一應用程序中運行,我做平常查找:
Properties p = new Properties();
// optional. Defaults to localhost. Only needed if web server is running
// on a different host than the appserver
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// optional. Defaults to 3700. Only needed if target orb port is not
// 3700.
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
Context context = new InitialContext(p);
// Stores the list of reachable EJBs
return context.lookup(interfacesToNames.getProperty(className));
不幸的是,這樣做的時候,我得到的是
Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com/sun/enterprise/naming/impl/SerialInitContextFactory]
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)
... 6 more
Caused by: java.lang.ClassNotFoundException: com/sun/enterprise/naming/impl/SerialInitContextFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
... 9 more
一些檢查之後,我諾蒂奇編輯我的glassfish-naming-3.1.jar
是存在於該客戶端應用程序的CLASSPATH中。而且,根據Eclipse代碼查找,這個jar應該包含com.sun.enterprise.naming.impl.SerialInitContextFactory
。但是,如果在調試模式下,我做getClass().getClassLoader().getResource("com/sun/enterprise/naming/impl/SerialInitContextFactory")
它返回我空,這清楚地表明該類無法找到。
欲瞭解更多的相關信息,該JAR是從我的本地倉庫使用此插件配置複製:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>package output directory</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<prependGroupId>true</prependGroupId>
<includeScope>compile</includeScope>
<outputDirectory>${dependencies.outputDir}/jars</outputDirectory>
<prefix>${dependencies.outputDir}</prefix>
</configuration>
</execution>
</executions>
</plugin>
此外,我不得不承認的是,使用相同的API連接到Glassfish的運行一個簡單的測試時,服務器,這絕對沒有問題,這導致我到ClassLoader問題。
當運行該客戶端時,當前類加載器是(如getClass().getClassLoader().getClass().getName()
所示)sun.misc.Launcher$AppClassLoader
。不幸的是,與運行單元測試完全相同。
那麼,我能做些什麼來解決這個錯誤?
編輯類存在於glassfish-naming-3.1.jar
,但似乎沒有找到標準的類加載器。
編輯一個有趣的發現:
getClass().getClassLoader().getResource("com/sun/enterprise/naming/impl") = jar:file:/C:/Users/pouet/pouet/target/jars/glassfish-naming-3.1.jar!/com/sun/enterprise/naming/impl
而
getClass().getClassLoader().getResource("com/sun/enterprise/naming/impl/SerialInitContextFactory") = null
請爲項目提交一個錯誤。 – Preston