简体   繁体   English

在端口号3700 glashfish Server上使用JNDI从客户端访问EJB 3.1

[英]Accessing EJB 3.1 from the client using the JNDI on port no 3700 glashfish Server

I am using netbeans IDE 7.1.2 and I have created an EJB 3.1 Stateless Bean and implemented remote as well as local interfaces both and deployed it to the glassfish server 3.2.1 successfully...here is the Code 我正在使用netbeans IDE 7.1.2,并且创建了EJB 3.1无状态Bean,并实现了远程和本地接口,并将其成功部署到glassfish服务器3.2.1中。

__ _ __ _ __ _ __ _ __ _ __ _ ___ CaseInfo.java _ __ _ __ _ __ _ __ _ __ _ __ __ _ __ _ __ __ _ _ _ __ __ _ ___ CaseInfo.java _ __ _ __ __ _ _ _ __ __ __ _

enter code here

package maxx;

import javax.ejb.Stateless;

@Stateless(name="CaseInfo",mappedName="CaseInfoBean")
public class CaseInfo implements CaseInfoRemote, CaseInfoLocal {

@Override
public String MyCaseMessageLocal() {
    return "Hello this is my Local message.";
}

@Override
public String MyCaseMessageRemote() {
    return "Hello this is my Remote message.Please Note that this message is comming from the remote";
}

}

__ _ __ _ __ _ __ _ __ _ __ _ CaseInfoLocal.java _ __ _ __ _ __ _ __ _ __ _ ___ __ _ __ _ __ __ _ _ _ __ __ _ _ CaseInfoLocal.java __ _ __ _ __ __ _ _ _ __ ___

package maxx;

import javax.ejb.Local;

@Local
public interface CaseInfoLocal {

String MyCaseMessageLocal();

}

__ _ __ _ __ _ __ _ __ _ __ CaseInfoRemote.java _ __ _ __ _ __ _ __ _ __ _ __ __ _ __ _ __ __ _ _ _ __ __ _ CaseInfoRemote.java __ _ __ _ __ __ _ _ _ __ __

package maxx;

import javax.ejb.Remote;

@Remote
public interface CaseInfoRemote {

String MyCaseMessageRemote();

}


now i have accessed it from locally successfully and after it i have created New Project>Java EE>Application Client project which is an desktop app hare i have accessed that bean successfully by adding jar file of bean module in to its library as a client Stub here is the some code 现在我已经成功地从本地访问了它,在创建了New Project> Java EE> Application Client项目之后,这是一个桌面应用程序,我已经通过将bean模块的jar文件作为客户端Stub添加到其库中而成功访问了该bean这是一些代码

__ _ __ _ __ _ __ _ __ _ __ _ ___ Main.java _ __ _ __ _ __ _ __ _ __ _ __ _ __ __ _ __ _ __ __ _ _ _ __ __ _ ___ Main.java _ __ _ __ __ _ _ _ __ __ _ __ __ _

package applicationclient;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import maxx.CaseInfoRemote;

public class Main {


public static void main(String arg[]) {

    try {
Properties prop = new Properties();
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                          "com.sun.enterprise.naming.SerialInitContextFactory");
prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); 

        InitialContext ic = new InitialContext(prop);
        Object ref = ic.lookup("CaseInfoBean");
        CaseInfoRemote home = (CaseInfoRemote)PortableRemoteObject.narrow(ref,
                CaseInfoRemote.class);
        System.out.println(home.MyCaseMessageRemote());

    } catch(Exception e) {
        e.printStackTrace();
    }
}
}

but when I am using this client accessing code go to New Project>java>java Application and writing here the same code so the problem showing that 但是当我使用此客户端访问代码时,请转到“新建项目”>“ java”>“ java应用程序”,并在此处编写相同的代码,因此该问题表明

__ _ __ _ __ _ __ _ __ _ __ _ ____ ERROR _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _ __ _ __ _ __ _ __ __ _ __ _ __ _ ____ 错误 _ __ _ __ _ __ _ __ _ __ __ _ __ _ __ _ _ _

run:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is  java.lang.ClassNotFoundException: com.sun.enterprise.naming.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)
at testcasebean.TestCaseBean.main(TestCaseBean.java:30)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    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)
    ... 4 more
BUILD SUCCESSFUL (total time: 0 seconds)

and if i am removing properties lines of code so is giving this type of ERROR 如果我要删除属性的代码行,则给出这种类型的错误

run: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: 运行:javax.naming.NoInitialContextException:需要在环境或系统属性中或作为applet参数或在应用程序资源文件中指定类名称:

java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at testcasebean.TestCaseBean.main(TestCaseBean.java:27)
BUILD SUCCESSFUL (total time: 0 seconds)

please tell how can i access this bean through using simple java desktop application because its no problem to using Java EE application Client but same code is giving these error 请告诉我如何通过使用简单的Java桌面应用程序访问此bean,因为与使用Java EE应用程序客户端没有问题,但是相同的代码给出了这些错误

You are probably not following the instructions how to access remote EJB's - deployed on a GlassFish server - from standalone Java clients. 您可能没有遵循如何从独立的 Java客户端访问部署在GlassFish服务器上的远程EJB的说明。 It is not entirely trivial. 这并非完全无关紧要。

This should answer your question. 这应该可以回答您的问题。 In general, I am suspecting that what you're missing is the gf-client.jar file in your classpath. 通常,我怀疑您缺少的是类路径中的gf-client.jar文件。 Follow the instructions and let us know: 请按照说明进行操作,并告诉我们:

http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#StandaloneRemoteEJB

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM