生成Weblogic的EJB3的客户端JAR

    在访问Weblogic中的EJB3的应用的时候,在客户端经常会有这样一些错误: NoSuchMethodError, CORBA errors,the following Kind of Stack Trace at client end, while invoking the EJB methods:

     java.lang.AssertionError: java.lang.ClassNotFoundException: com.veris.billing.GetCartCredit
     at weblogic.ejb.container.internal.RemoteBusinessIntfGenerator.generateRemoteInterface   (RemoteBusinessIntfGenerator.java:57)
     at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.readObject (RemoteBusinessIntfProxy.java:205)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)

例如:

 http://forums.oracle.com/forums/thread.jspa?threadID=839694&tstart=0

   

 

    下面说明一下如何生成Weblogic使用的EJB3客户端JAR。
    假设原始的EJB3的JAR文件是 “SFSB_EJB3.jar” 位于 “C:\CustomJNDIName\build”目录。其中没有包括部署描述符。

 

  我们使用“weblogic.appc”来生成。

先初始化环境:

%BEA_HOME%\wlserver_10.3\server\bin\setWLSEnv.cmd

再运行:

C:\CustomJNDIName\build> java weblogic.appc -source 1.5 -output OUTPUT -writeInferredDescriptors -verbose SFSB_EJB3.jar

 

打开位于“C:\CustomJNDIName\build” 下OUTPUT目录,其中“META-INF”目录下有默认的EJB3 描述文件,如下:

“ejb-jar.xml”

<?xml version=’1.0′ encoding=’UTF-8′?>
<ejb-jar xmlns=”http://java.sun.com/xml/ns/javaee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” metadata-complete=”true”>
<enterprise-beans>
<session>
<ejb-name>ReplicableSFSBean</ejb-name>
<business-local>sfsb3.ReplicableSFSLocalIntf</business-local>
<business-remote>sfsb3.ReplicableSFSRemoteIntf</business-remote>
<ejb-class>sfsb3.ReplicableSFSBean</ejb-class>
<session-type>Stateful</session-type>
<remove-method>
<bean-method>
<method-name>removeWithRetain</method-name>
<method-params></method-params>
</bean-method>
<retain-if-exception>true</retain-if-exception>
</remove-method>
<remove-method>
<bean-method>
<method-name>removeWithoutRetain</method-name>
<method-params></method-params>
</bean-method>
<retain-if-exception>false</retain-if-exception>
</remove-method>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor></assembly-descriptor>
</ejb-jar>

 

 

默认的 “weblogic-ejb-jar.xml” 如下:

<weblogic-ejb-jar xmlns=”http://www.bea.com/ns/weblogic/weblogic-ejb-jar” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd”>
</weblogic-ejb-jar>

  
现在编辑“ejb-jar.xml” 文件,添加 <ejb-client-jar>My_Ejb3_Client.jar</ejb-client-jar> Tag 到其中. 如下:

 

<?xml version=’1.0′ encoding=’UTF-8′?>
<ejb-jar xmlns=”http://java.sun.com/xml/ns/javaee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” metadata-complete=”true”>
<enterprise-beans>
<session>
<ejb-name>ReplicableSFSBean</ejb-name>
<business-local>sfsb3.ReplicableSFSLocalIntf</business-local>
<business-remote>sfsb3.ReplicableSFSRemoteIntf</business-remote>
<ejb-class>sfsb3.ReplicableSFSBean</ejb-class>
<session-type>Stateful</session-type>
<remove-method>
<bean-method>
<method-name>removeWithRetain</method-name>
<method-params></method-params>
</bean-method>
<retain-if-exception>true</retain-if-exception>
</remove-method>
<remove-method>
<bean-method>
<method-name>removeWithoutRetain</method-name>
<method-params></method-params>
</bean-method>
<retain-if-exception>false</retain-if-exception>
</remove-method>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor></assembly-descriptor>
<ejb-client-jar>My_Ejb3_Client.jar</ejb-client-jar>
</ejb-jar>

  

现在编辑 “weblogic-ejb-jar.xml” 文件,添加JNDI名到其中,如下:

<weblogic-ejb-jar xmlns=”http://www.bea.com/ns/weblogic/90″ xmlns:j2ee=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd”>
<weblogic-enterprise-bean>
<ejb-name>ReplicableSFSB</ejb-name>
<stateful-session-descriptor>
<business-interface-jndi-name-map>
<business-remote>sfsb3.ReplicableSFSRemoteIntf </business-remote>
<jndi-name>ReplicableSFSB</jndi-name>
</business-interface-jndi-name-map>
</stateful-session-descriptor>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
 

现在你可以重新组装你的EJB, 在如下的位置:

 “C:\CustomJNDIName\build\OUTPUT”.

在DOS的命令窗口进入上面的目录执行“setWLSEnv.cmd”,再执行如下操作:

 

C:\CustomJNDIName\build\OUTPUT> jar cvf Edited_SFSB_EJB3.jar .

C:\CustomJNDIName\build\OUTPUT> jar cvf Edited_SFSB_EJB3.jar META-INF sfsb3

C:\CustomJNDIName\build\OUTPUT> jar cvf Edited_SFSB_EJB3.jar META-INF sfsb3 _WL_GENERATED

注意:classpath中不要包括. 。

 

     现在“Edited_SFSB_EJB3.jar” 可以用于部署了,但我们还要生成客户端的JAR。因此需要新建一个BUILD文件 “buildClientJar.xml”“C:\CustomJNDIName\build\OUTPUT”目录中,内容如下:

<project name=”Test-Client_Jar_EJB3″ default=”deploy” basedir=”.”>
<property name=”wl.home.lib” value=”C:\bea103\wlserver_10.3\server\lib” />
<property name=”wls.username” value=”weblogic” />
<property name=”wls.password” value=”weblogic” />
<property name=”wls.hostname” value=”localhost” />
<property name=”wls.port” value=”7001″ />
<property name=”admin.server.name” value=”AdminServer” />
<property name=”deploy.target” value=”AdminServer” />
<property name=”src.dir” value=”src”/>
<property name=”build.dir” value=”build”/>
<property name=”classes.dir” value=”${build.dir}/classes”/>
<property name=”jar.dir” value=”${build.dir}”/>
<property name=”jar.file.name” value=”Edited_SFSB_EJB3″/>
<property name=”deploy.name” value=”Edited_SFSB_EJB3″ />
<property name=”deploy.source” value=”Edited_SFSB_EJB3.jar” />
<path id=”custom.classpath”>
<fileset dir=”${wl.home.lib}”>
<include name=”*.jar”/>
</fileset>
</path>
<taskdef name=”weblogicAppc” classpathref=”custom.classpath” classname=”weblogic.ant.taskdefs.j2ee.Appc”/>
<taskdef name=”wldeploy” classname=”weblogic.ant.taskdefs.management.WLDeploy”/>
<target name=”appc”>
<weblogicAppc source=”${jar.file.name}.jar”
keepgenerated=”true”
verbose=”true”
output=”.”
clientJarOutputDir=”.”
/>
</target>
<target name=”deploy” depends=”appc”>
<wldeploy action=”deploy” name=”${deploy.name}” source=”${deploy.source}” user=”${wls.username}” nostage=”true”
password=”${wls.password}” verbose=”true” adminurl=”t3://${wls.hostname}:${wls.port}” targets=”${deploy.target}” />
</target>
<target name=”redeploy”>
<wldeploy action=”redeploy” name=”${deploy.name}” user=”${wls.username}” nostage=”true” source=”${deploy.source}”
password=”${wls.password}” verbose=”true” adminurl=”t3://${wls.hostname}:${wls.port}” targets=”${deploy.target}” />
</target>
<target name=”undeploy”>
<wldeploy action=”undeploy” name=”${deploy.name}” failonerror=”false” user=”${wls.username}”
password=”${wls.password}” verbose=”true” adminurl=”t3://${wls.hostname}:${wls.port}” targets=”${deploy.target}” />
</target>
</project>
 

 

 

C:\CustomJNDIName\build\OUTPUT> ant -buildfile buildClientJar.xml

 

现在运行上面的 Ant 脚本后,“My_Ejb3_Client.jar” 客户端Jar 已经在当前目录生成,并且 EJB 也已经被部署到服务器了。

你可能感兴趣的:(xml,bean,weblogic,ant,ejb)