NullPointerException異常在InitialContext的的NullPointerException在InitialContext的
private void connect() {
try {
InitialContext ctx = new InitialContext();
IServerBean serverBean = (IServerBean)ctx.
lookup("java:global/applicationserver/ServerBean!
com.test.applicationserver.IServerBean");
} catch (NamingException e) {
logger.error(e.getMessage(), e);
}
}
我得到這個異常,當嘗試通過控制檯執行java -cp cleint-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.test.client.EJBClient
客戶端應用程序:
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:335)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.createInitialContext
(SerialInitContextFactory.java:358)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext
(SerialInitContextFactory.java:353)
at com.sun.enterprise.naming.SerialInitContextFactory.getInitialContext
(SerialInitContextFactory.java:69)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at com.test.client.EJBClient.connect(EJBClient.java:33)
at com.test.client.EJBClient.main(EJBClient.java:61)
此應用程序連接到遠程EJB模塊。 但是當我嘗試在Eclipse中執行它時,一切都很順利。 我的配置:
- 的Java SE 1.7
- GlassFish應用服務器3.1.2.2版(版本5)
- 的Eclipse的Java EE IDE的Web開發。版本:朱諾服務發佈 1個版本ID:20121004-1855
Maven依賴:
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>C:\Java\jdk1.7.0_11\lib\tools.jar</systemPath>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>javaee</artifactId>
<version>3.1.2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.appclient</groupId>
<artifactId>gf-client</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
請標記爲已回答的問題。 – greenkode 2013-02-27 12:22:49