我在Netbeans中創建了一個簡單的企業應用程序,它在Netbeans中按預期工作。企業應用程序客戶端包含以下代碼:無法實例化類:com.sun.enterprise.naming.SerialInitContextFactory
package clienttest2;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import test.TestEJBRemote;
/**
*
* @author
*/
public class Main {
private TestEJBRemote testejb;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws NamingException {
Properties props = new Properties();
props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "computer");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);
TestEJBRemote t = (TestEJBRemote) ctx.lookup("java:global/EJBTest/EJBTest-ejb/TestEJB");
System.out.println(t.getName("Ian"));
//Context ctx = null;
//ctx=new InitialContext();
//TestEJBRemote t = (TestEJBRemote) ctx.lookup("java:global/EJBTest/EJBTest-ejb/TestEJB");
//System.out.println(t.getName("Ian"));
}
}
我曾嘗試以下:
java -jar ClientTest.jar
我得到的錯誤是:無法實例類:com.sun.enterprise.naming.SerialInitContextFactory
我有幾個問題:
我在我的電腦上安裝了JRE 1.8。這是否意味着我可以運行所有類型的Java應用程序,即Java EE和Java SE?
glassfish的appclient命令可能爲您解決這些依賴關係。 – Thufir