EJB Jndi 仅在 Java Web 启动时在 Glassfish 服务器中查找 [英] EJB Jndi look up in Glassfish server only in Java Web start

查看:22
本文介绍了EJB Jndi 仅在 Java Web 启动时在 Glassfish 服务器中查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Java Web start 连接到 glassfish 服务器中的 ejb 服务.获取初始上下文时出现以下错误.我还添加了用于获取初始上下文的代码片段.

I am trying to connect to the ejb service in glassfish server through Java Web start. I am getting the following error while getting the initial context. I have also added the code snippet for getting the initial context.

有趣的是,当我在 netbeans IDE 中将程序作为 java web start 之外的简单 java 程序运行时,它运行良好.

One interesting is when I run the program as a simple java program outside of java web start in a netbeans IDE, it is working fine.

我将 glassfish 模块文件夹中的所有相关 jar 文件添加到 java web start 中.

I added all the relevant jar files from the glassfish modules folder into the java web start.

java.lang.NullPointerException
    at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:275)
    at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:334)
    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 gov.ca.lc.util.ServiceLocator.getInitialContext(ServiceLocator.java:140)
    at gov.ca.lc.util.ServiceLocator.getVotesEJB(ServiceLocator.java:103)
    at gov.ca.lc.scenemanagement.AbstractVotingScene.getCommitteeList(AbstractVotingScene.java:143)
    at gov.ca.lc.scenemanagement.AbstractVotingScene.<init>(AbstractVotingScene.java:65)
    at gov.ca.lc.scenes.MenuScene.<init>(MenuScene.java:56)
    at gov.ca.lc.menu.StartVoting.startUp(StartVoting.java:47)
    at org.mt4j.MTApplication.setup(MTApplication.java:328)
    at processing.core.PApplet.handleDraw(PApplet.java:1580)
    at processing.core.PApplet.run(PApplet.java:1502)
    at java.lang.Thread.run(Unknown Source)
Exception in thread "Animation Thread" java.lang.NullPointerException
    at gov.ca.lc.scenemanagement.AbstractVotingScene.getCommitteeList(AbstractVotingScene.java:143)
    at gov.ca.lc.scenemanagement.AbstractVotingScene.<init>(AbstractVotingScene.java:65)
    at gov.ca.lc.scenes.MenuScene.<init>(MenuScene.java:56)
    at gov.ca.lc.menu.StartVoting.startUp(StartVoting.java:47)
    at org.mt4j.MTApplication.setup(MTApplication.java:328)
    at processing.core.PApplet.handleDraw(PApplet.java:1580)
    at processing.core.PApplet.run(PApplet.java:1502)
    at java.lang.Thread.run(Unknown Source)


Following is my code to get the initial context

    private static InitialContext getInitialContext()
            throws NamingException {
            Properties props = null;
            try{  
    //            props=new Properties();   
    //            props.load(new FileInputStream(new File("jndi.properties")));
    //            System.out.println(props.get("java.naming.factory.initial"));
                 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");//ur server ip  
        props.setProperty("java.naming.factory.state ", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");//ur server ip  
        props.setProperty("org.omg.CORBA.ORBInitialHost", "165.107.33.181");//ur server ip  
        props.setProperty("org.omg.CORBA.ORBInitialPort","3700"); //default is 3700  


            }catch(Exception ex){
                ex.printStackTrace();
            }
            return new InitialContext(props);
        }

推荐答案

我想补充一点,只有在您的机器中安装了 glassfish 时,所有这些设置才会起作用.如果您在没有 glassfish 服务器的机器上部署 java webstart 应用程序,那么我们最终会得到相同的异常.原因是如果你打开 appserv-rt.jar 它指向 gf-client.jar,如果你查看 gf-client.jar 它指向模块文件夹中的一大堆 jar 文件.所以我想,本质上我们需要 gf-client.jar 指向的所有 jar 文件.

I would like to add that all these set up will work only if you have the glassfish installed in your machine. If you deploy the java webstart app in a machine which doesn't have the glassfish server then we will end up getting the same exception. The reason is that if you open the appserv-rt.jar it points to the gf-client.jar and if you look into the gf-client.jar it points to a whole bunch of jar files in modules folder. So I suppose, essentially we need the all the jar files pointed by the gf-client.jar.

这篇关于EJB Jndi 仅在 Java Web 启动时在 Glassfish 服务器中查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆