如何在JBoss 下部署EJB?

03-09-02 kitta
我是一个EJB初学者,在部署EJB时碰到了好多麻烦。

在Sun application server上失败了,因为部署工具总说我的ear是坏的!

在jboss下也不行,在我的servlet/jsp中找不到我指定的JNDI名字。

我用的是examples\org\jboss\docs\interest这个例子,

源代码丁点儿没动,因为它的build.xml有些问题,主要是路径,稍微改了一下,附在最后。

另外,部署一个ear,war 或者ejb jar的时候,只要copy到%jboss_dist%/server/default/deploy下就可以了么?

不用restart jboss?

我的系统是WinXP professional sp1, j2ee 1.4 beta 2, jboss-4.0.0DR2,我也不太清楚JBOSS的版本区别,

只是挑了个最新的down了下来 ^^

用modem down的,好辛苦,就看在我这份执著上,请大家不吝赐教吧!真的,我都快抓墙了!

build.xml
--------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8" ?>
<!-- An Ant build file for the Interest EJB example
-->

<project name="Interest Build Script" default="ejb-jar" basedir=".">
	<property environment="env"/>
    <property name="build.interest.dir" value="${basedir}/build-examples/interest"/>
    <property name="build.classes.dir" value="${basedir}/build-examples/interest/classes"/>
    <property name="src.dir" value="${basedir}"/>
	<property name="example.root" value="${basedir}/../../../../"/>
	<property name="jboss.dist" value="${env.JBOSS_DIST}/server/default"/>

    <target name="compile">
      <mkdir dir="${build.classes.dir}"/>
      <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           debug="on"
           deprecation="on"
           optimize="off"
		   classpath="${env.J2EE_HOME}/lib/j2ee.jar"/>
    </target>

    <target name="compile-servlet">
      <mkdir dir="${build.classes.dir}"/>
      <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           debug="on"
           deprecation="on"
           optimize="off"
      >
       <classpath path="${example.root}" />
       <include name="org/jboss/docs/interest/InterestServlet.java" />
      </javac>
    </target>

    <!-- Tutorial ejb jar -->
    <target name="ejb-jar" depends="compile">
        <delete dir="${build.interest.dir}/META-INF"/>
        <mkdir dir="${build.interest.dir}/META-INF"/>
        <copy file="${src.dir}/ejb-jar.xml" todir="${build.interest.dir}/META-INF" />
        <copy file="${src.dir}/jboss.xml" todir="${build.interest.dir}/META-INF" />
        <jar jarfile="${build.interest.dir}/interest.jar">
            <fileset dir="${build.classes.dir}">
                <include name="org/jboss/docs/interest/Interest.class" />
                <include name="org/jboss/docs/interest/InterestHome.class" />
                <include name="org/jboss/docs/interest/InterestBean.class" />
            </fileset>
            <fileset dir="${build.interest.dir}">
                <include name="META-INF/ejb-jar.xml" />
                <include name="META-INF/jboss.xml" />
            </fileset>
        </jar>
    </target>

    <!-- Tutorial web app war -->
    <target name="war" depends="compile-servlet">
        <delete dir="${build.interest.dir}/WEB-INF"/>
        <mkdir dir="${build.interest.dir}/WEB-INF/classes/org/jboss/docs/interest"/>
        <copy file="${src.dir}/web.xml" todir="${build.interest.dir}/WEB-INF" />
        <copy file="${src.dir}/jboss-web.xml" todir="${build.interest.dir}/WEB-INF" />
        <copy file="${src.dir}/home.html" todir="${build.interest.dir}" />
        <copy file="${build.classes.dir}/org/jboss/docs/interest/InterestServlet.class" todir="${build.interest.dir}/WEB-INF/classes/org/jboss/docs/interest" />
        <jar jarfile="${build.interest.dir}/interest.war">
            <fileset dir="${build.interest.dir}">
                <include name="WEB-INF/**"/>
                <include name="home.html"/>
            </fileset>
        </jar>
    </target>
    <!-- Create the tutorial ear that uses the properties based security info -->
    <target name="ear" depends="ejb-jar,war">
        <copy file="${src.dir}/application.xml" todir="${build.interest.dir}/META-INF" />
        <jar jarfile="${build.interest.dir}/interest.ear">
            <fileset dir="${build.interest.dir}">
                <include name="META-INF/application.xml" />
                <include name="interest.jar" />
                <include name="interest.war" />
            </fileset>
        </jar>
    </target>

    <target name="deploy-ejb-jar" depends="ejb-jar">
        <copy file="${build.interest.dir}/interest.jar" todir="${jboss.dist}/deploy" />
    </target>
    <target name="deploy-ear" depends="ear">
        <copy file="${build.interest.dir}/interest.ear" todir="${jboss.dist}/deploy" />
    </target>

    <target name="interest-client" depends="compile">
        <java classname="org.jboss.docs.interest.InterestClient" fork="yes">
            <classpath>
               <pathelement location="${build.classes.dir}"/>
            </classpath>
        </java>
    </target>
</project>

猜你喜欢