I used zipfilesets to include the hibernate jar and associated jars in my application jar. Here's my build.xml that I run from within eclipse:
<?xml version="1.0" encoding="utf-8"?>
<project name="mainapp" default="Build" basedir=".">
<property name="srcDir" location="${basedir}" />
<property name="binDir" location="${basedir}/../../bin/" />
<property name="libDir" location="${basedir}/mainapp/lib" />
<property name="dataDir" location="${basedir}/mainapp/data" />
<property name="jarDir" location="${binDir}" />
<property name="classDir" location="${basedir}/mainapp/classes" />
<property name="jarFile" location="${jarDir}/mainapp.jar" />
<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include our own classes, of course -->
<pathelement location="${classDir}" />
<!-- Include jars in the project library directory -->
<fileset dir="${libDir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="Initialization">
<echo message="Deleting class directory"/>
<delete dir="${classDir}" quiet="true"/>
<echo message="Creating class directory"/>
<mkdir dir="${classDir}"/>
<echo message="basedir ${basedir}" />
<echo message="src ${srcDir}" />
<echo message="bin ${binDir}" />
<echo message="lib ${libDir}" />
<echo message="data ${dataDir}" />
<echo message="class ${classDir}" />
<echo message="jar ${jarDir}" />
<echo message="Deleting class files." />
<!-- Copy our property files and O/R mappings for use at runtime -->
<copy todir="${classDir}">
<fileset dir="${srcDir}">
<include name="**/*.properties" />
<include name="**/*.hbm.xml" />
<include name="**/*.xml" />
</fileset>
</copy>
<copy todir="${classDir}">
<fileset dir="${srcDir}">
<include name="**/*.gif" />
</fileset>
<fileset dir="${srcDir}">
<include name="**/*.gif" />
</fileset>
</copy>
</target>
<target name="Compilation" depends="Initialization">
<echo message="Compiling Java source" />
<javac srcdir="${srcDir}" destdir="${classDir}" debug="on" optimize="off" deprecation="on">
<classpath refid="project.class.path" />
</javac>
</target>
<target name="Jar" depends="Initialization, Compilation">
<echo message="Creating mainapp.jar" />
<jar destfile="${jarFile}" basedir="${classDir}">
<zipfileset dir="${classDir}" prefix="" />
<zipfileset src="${libDir}/antlr-2.7.5H3.jar"/>
<zipfileset src="${libDir}/asm-attrs.jar"/>
<zipfileset src="${libDir}/asm.jar"/>
<zipfileset src="${libDir}/cglib-2.1.jar"/>
<zipfileset src="${libDir}/commons-collections-2.1.1.jar"/>
<zipfileset src="${libDir}/commons-logging-1.0.4.jar"/>
<zipfileset src="${libDir}/dom4j-1.6.jar"/>
<zipfileset src="${libDir}/ehcache-1.1.jar"/>
<zipfileset src="${libDir}/hibernate3.jar"/>
<zipfileset src="${libDir}/jdbc2_0-stdext.jar"/>
<zipfileset src="${libDir}/jta.jar"/>
<zipfileset src="${libDir}/log4j-1.2.9.jar"/>
<zipfileset src="${libDir}/mysql-connector-java-3.1.10-bin.jar"/>
<zipfileset src="${libDir}/xml-apis.jar"/>
<include name="**/*.class" />
<include name="**/*.gif" />
<manifest>
<attribute name="Main-Class" value="mainapp.main" />
</manifest>
</jar>
</target>
<target name="Build" depends="Initialization, Compilation, Jar">
<echo message="Building main." />
</target>
<target name="test" description="Run the test driver"
depends="Initialization, Compilation">
<java classname="mainapp.TestDriver" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>
</project>
_________________ Don't forget to rate!
|