Jungi's Blog...


« Java EE application... | Main | tcpmon in NetBeans... »
Thursday Oct 19, 2006

Export EJB client jar in NetBeans 5.5 & 6.1

Using Export EJB Interfaces module

UPDATE 5/22/2008: Module updated to work with NetBeans 6.1 FCS.

Changes:
  • Export EJB Interfaces moved directly to project's context menu

After installing Export EJB Client Jar module using Tools -> Update Center you can see new Export EJB Interfaces action in EJB module's context menu -> Tools section. This action does nothing else then it creates new ant script in nbproject/private directory which overrides few targets from nbproject/build-impl.xml and executes this new script. After execution you should see two jars in the dist directory - one which is ready to be deployed (it contains EJB implementation classes, DDs and required libraries) and second which can be shared w/ other modules/applications (it contains only EJB interfaces and helper classes which are used by interfaces). For NetBeans 5.5 you can get the module here and its sources here

Note: If you invoke Deploy action after the Export ... action then the Deploy action will add EJB interfaces to the final jar containing implementation classes. See the next section if you want to override this behaviour of the Deploy action by default.





Creating EJB client jar as a part of build process

The build script generated by the Export EJB Interfaces action looks like following one:

<?xml version="1.0" encoding="UTF-8"?>
<project name="export-ejb-interfaces" basedir="../.." default="export">
    <import file="../build-impl.xml"/>
    <!--
                TODO: client jar for ejb module will be created iff
                "ejb.interfaces" property will be set eg. this way:
                <property name="ejb.interfaces" value="my/ejb/TestedRemote.java my/ejb/TestedLocal.java"/>
            -->

    <target name="-client-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-copy-meta-inf" if="ejb.interfaces">
        <mkdir dir="${build.generated.dir}/ejbclient"/>
        <javac srcdir="${src.dir}" listfiles="true" includes="${ejb.interfaces}"
                  destdir="${build.generated.dir}/ejbclient" debug="${javac.debug}"
                  deprecation="${javac.deprecation}" source="${javac.source}"
                  target="${javac.target}" includeantruntime="false">
            <classpath>
                <path path="${javac.classpath}:${j2ee.platform.classpath}"/>
            </classpath>
        </javac>
    </target>

    <target name="-do-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-client-compile,-copy-meta-inf" if="have.sources">
        <javac srcdir="${src.dir}" listfiles="true" destdir="${classes.dir}"
                  debug="${javac.debug}" deprecation="${javac.deprecation}" source="${javac.source}"
                  target="${javac.target}" includeantruntime="false">
            <classpath>
                <path path="${javac.classpath}:${j2ee.platform.classpath}:${build.generated.dir}/ejbclient"/>
            </classpath>
            <not>
                <present targetdir="${build.generated.dir}/ejbclient">
                    <mapper type="glob" from="*.java" to="*.class"/>
                </present>
            </not>
        </javac>
        <copy todir="${classes.dir}">
            <fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
        </copy>
    </target>


    <target name="-client-jar" depends="-client-compile" if="ejb.interfaces">
        <mkdir dir="${dist.dir}"/>
        <jar jarfile="${dist.dir}/TestEJB-client.jar" compress="${jar.compress}">
            <fileset dir="${build.generated.dir}/ejbclient"/>
        </jar>
        <copy file="${dist.dir}/TestEJB-client.jar" todir="${build.classes.dir}"/>
    </target>

    <target name="-do-dist" depends="init,compile,-pre-dist,-client-jar,library-inclusion-in-archive,-do-dist-without-manifest,-do-dist-with-manifest"/>

    <target name="-check-javaee-version" depends="init">
        <condition property="java.ee.project">
            <equals arg1="${j2ee.platform}" arg2="1.5"/>
        </condition>
    </target>

    <target name="-client-jar-ear" depends="-client-compile" if="ejb.interfaces">
        <mkdir dir="${dist.dir}"/>
        <jar jarfile="${dist.dir}/TestEJB-client.jar" compress="${jar.compress}">
            <fileset dir="${build.generated.dir}/ejbclient"/>
        </jar>
        <mkdir dir="${dist.ear.dir}/lib"/>
        <copy file="${dist.dir}/TestEJB-client.jar" todir="${dist.ear.dir}/lib"/>
    </target>

    <target name="-library-inclusion-in-manifest" depends="-check-javaee-version" unless="java.ee.project">
        <antcall target="library-inclusion-in-manifest"/>
    </target>

    <target name="-do-ear-dist" depends="init,compile,-pre-dist,-client-jar-ear,-library-inclusion-in-manifest">
        <dirname property="dist.jar.dir" file="${dist.ear.jar}"/>
        <mkdir dir="${dist.jar.dir}"/>
        <jar jarfile="${dist.ear.jar}" compress="${jar.compress}" manifest="${build.ear.classes.dir}/META-INF/MANIFEST.MF">
            <fileset dir="${build.ear.classes.dir}"/>
        </jar>
    </target>

    <target name="export" depends="dist"/>
</project>

If you want to create EJB client jar as a part of build process automatically just put the targets from build script generated by the "special" action (or copy & paste the ones above) to your EJB module's build.xml, replace there TestEJB-client.jar with the name you want to use for your jar and set the ejb.interfaces property at the beginning of the build script.

Comments:

Post a Comment:
Comments are closed for this entry.

Today's Page Hits: 19