tags:

views:

283

answers:

2

Hi, I am trying to make an ant script for an EJB project. I am using Jboss for this. I am new to both EJB and Ant and am having problems in getting the beans to compile from ant. It gives me number of errors of the kind package javax.persistence does not exist @MappedSuperclass - Cannot find symbol

I created it as an eclipse project initially, and added the jboss runtime through eclipse. Do I need to copy all the jars in a lib folder and include them in the classpath for the beans to compile or is there a better way to do this?

A: 

Try setting classpath in Ant appropriately. It ignores any system CLASSPATH or Eclipse setting that you have.

Here's an Ant build.xml that you can start with:

<?xml version="1.0" encoding="UTF-8"?>
<project name="spring-finance" basedir="." default="package">

    <property name="version" value="1.6"/>
    <property name="haltonfailure" value="no"/>

    <property name="out" value="out"/>

    <property name="production.src" value="src/main/java"/>
    <property name="production.lib" value="src/main/webapp/WEB-INF/lib"/>
    <property name="production.resources" value="src/main/resources"/>
    <property name="production.classes" value="${out}/production/${ant.project.name}"/>

    <property name="test.src" value="src/test/java"/>
    <property name="test.lib" value="src/test/lib"/>
    <property name="test.resources" value="src/test/resources"/>
    <property name="test.classes" value="${out}/test/${ant.project.name}"/>

    <property name="exploded" value="out/exploded/${ant.project.name}"/>
    <property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
    <property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>

    <property name="reports.out" value="${out}/reports"/>
    <property name="junit.out" value="${reports.out}/junit"/>

    <property name="web.src" value="src/main/webapp"/>
    <property name="web.lib" value="${web.src}/WEB-INF/lib"/>
    <property name="web.classes" value="${web.src}/WEB-INF/classes"/>

    <path id="production.class.path">
        <pathelement location="${production.classes}"/>
        <pathelement location="${production.resources}"/>
        <fileset dir="${production.lib}">
            <include name="**/*.jar"/>
            <exclude name="**/junit*.jar"/>
            <exclude name="**/*test*.jar"/>
        </fileset>
    </path>

    <path id="test.class.path">
        <path refid="production.class.path"/>
        <pathelement location="${test.classes}"/>
        <pathelement location="${test.resources}"/>
        <fileset dir="${test.lib}">
            <include name="**/junit*.jar"/>
            <include name="**/*test*.jar"/>
        </fileset>
    </path>

    <available file="${out}" property="outputExists"/>

    <target name="clean" description="remove all generated artifacts" if="outputExists">
        <delete dir="${out}" includeEmptyDirs="true"/>
    </target>

    <target name="create" description="create the output directories" unless="outputExists">
        <mkdir dir="${production.classes}"/>
        <mkdir dir="${test.classes}"/>
        <mkdir dir="${junit.out}"/>
        <mkdir dir="${exploded.classes}"/>
        <mkdir dir="${exploded.lib}"/>
    </target>

    <target name="compile" description="compile all .java source files" depends="create">
        <!-- Debug output
                <property name="production.class.path" refid="production.class.path"/>
                <echo message="${production.class.path}"/>
        -->
        <javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
            <classpath refid="production.class.path"/>
            <include name="**/*.java"/>
            <exclude name="**/*Test.java"/>
        </javac>
        <javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
            <classpath refid="test.class.path"/>
            <include name="**/*Test.java"/>
        </javac>
    </target>

    <target name="test" description="run all unit tests" depends="compile">
        <!-- Debug output
                <property name="test.class.path" refid="test.class.path"/>
                <echo message="${test.class.path}"/>
        -->
        <junit printsummary="yes" haltonfailure="${haltonfailure}">
            <classpath refid="test.class.path"/>
            <formatter type="xml"/>
            <batchtest fork="yes" todir="${junit.out}">
                <fileset dir="${test.src}">
                    <include name="**/*Test.java"/>
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="${junit.out}">
            <fileset dir="${junit.out}">
                <include name="TEST-*.xml"/>
            </fileset>
            <report todir="${junit.out}" format="frames"/>
        </junitreport>
    </target>

    <target name="exploded" description="create exploded deployment" depends="test">
        <copy todir="${exploded}">
            <fileset dir="${web.src}"/>
        </copy>
        <copy todir="${exploded}/WEB-INF">
            <fileset dir="${web.src}/WEB-INF"/>
        </copy>
        <copy todir="${exploded.classes}">
            <fileset dir="${production.classes}"/>
        </copy>
        <copy todir="${exploded.lib}">
            <fileset dir="${production.lib}"/>
        </copy>
    </target>

    <target name="jar" description="create jar file" depends="test">
        <jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
    </target>

    <target name="war" description="create war file" depends="exploded">
        <war basedir="${exploded}" webxml="${exploded}/WEB-INF/web.xml" destfile="${out}/${ant.project.name}.war"/>
    </target>

    <target name="package" description="create package for deployment" depends="test">
        <antcall target="war"/>
    </target>

</project>
duffymo
A: 

So when I include hibernate3.jar,hibernate-tools.jar and mysql-connector-java-5.1.8-bin.jar to the classpath while compiling the ejb project. It gives me errors or these kind

[javac] C:\Users\User\workspace - new\mirror-ejb\ejbModule\osu\mirror\example\entity\core\StringTuple.java:13: package javax.persistence does not exist [javac] import javax.persistence.Basic;

So what other jars should I be including in the path ?

Vineet
Having the same problem here.
GreenKiwi