如何为WebSphere 8.5编写EJB 3.1客户端?

Man*_*aik 6 websphere java-ee ejb-3.1

在查找部署在WebSphere 8.5上的EJB 3.1时,我遇到了问题.

请建议我:

  1. 我需要在classpath中包含哪些库?
  2. 如何构造查找字符串?
  3. 是否需要在服务器端更改任何设置?

注意:我正在使用Eclipse IDE

Man*_*aik 6

试试这个 :

  1. 添加com.ibm.ws.ejb.thinclient_8.5.0.jarcom.ibm.ws.orb_8.5.0.jarjar到客户端应用程序的类路径.
  2. 通过运行createEJBStubs.sh脚本生成客户端存根.
    createEJBStubs.sh<WAS_HOME>/bin目录下找到的脚本.
    句法 :./createEJBStubs.sh <ejbJarName>.jar
  3. 将生成的jar添加到客户端应用程序的类路径中.
  4. 按如下方式JNDI为您提供自定义名称EJB:
    打开WebSphere控制台,在左侧面板上单击Applications>All applications.
    单击已部署的应用程序.
    点击Bind EJB Business下面Enterprise Java Bean Properties. 为您的下栏
    设置自定义JNDI名称.例如EJBJNDI namecustomLookupString

客户代码示例:

public class WebSphereClient {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.ibm.websphere.naming.WsnInitialContextFactory");
        props.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2818");
        TestBeanRemote bean = null;
        Object obj;
        try {
            InitialContext ctx = new InitialContext(props);
            obj= ctx.lookup("customLookupString");
            if (obj instanceof TestBeanRemote) {
                bean = (TestBeanRemote) obj;
            }
            System.out.println("Name : "+bean.getName());
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

以上代码和流程对我有用.


Gas*_*Gas 5

查看此页面运行IBM Thin Client for Enterprise JavaBeans(EJB)以获取更多详细信息.

我需要在classpath中包含哪些库?

您将需要com.ibm.ws.ejb.thinclient_8.5.0.jar(位于app_server_root\runtimes)和endorsed_apis_8.5.0.jar(位于app_server_root\runtimes\endorsed中).将endoresed jar复制到JAVA_JRE\lib\endorsed

如何构造查找字符串?

像这样调用你的应用程序:

<java_install_root>\bin\java  
-classpath com.ibm.ws.ejb.thinclient_8.5.0.jar;<list_of_your_application_jars_and_classes> 
-Djava.naming.provider.url=iiop://<your_application_server_machine_name>:<orbPort>
<fully_qualified_class_name_to_run>
Run Code Online (Sandbox Code Playgroud)

如果您在服务器上启用了安全性并且需要SSL,则需要添加以下内容:

-Dcom.ibm.SSL.ConfigURL=file:///home/user1/ssl.client.props
-Dcom.ibm.CORBA.ConfigURL=file:///home/user1/sas.client.props
Run Code Online (Sandbox Code Playgroud)

您可以在WebSphere安装文件中找到这些文件 PROFILE_ROOT\properties