我想將我的hibernate配置xml文件複製到屬於POJO內置的jar中。以下是我的Ant build.xml文件(我得到這個從here)Ant build不會複製xml文件
<project name="Ant-Test" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src"/>
<property name="build.dir" location="bin"/>
<property name="dist.dir" location="dist"/>
<property name="docs.dir" location="docs"/>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${docs.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}"/>
<mkdir dir="${docs.dir}"/>
<mkdir dir="${dist.dir}"/>
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath>
<pathelement path="/jars/log4j.jar"/>
</classpath>
</javac>
</target>
<!-- copy hbm files ${dist.dir} -->
<target name="copy-hbm" depends="compile" description="Copy hibernate files">
<copy todir="${build.dir}" >
<fileset dir="${src.dir}" includes="*.xml" />
</copy>
</target>
<!-- hbm copy over -->
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files/directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**"/>
</fileset>
</javadoc>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\my-hibernate-pojo.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="test.Main"/>
</manifest>
</jar>
</target>
<target name="main" depends="copy-hbm, jar">
<description>Main target</description>
</target>
</project>
這將生成jar文件,但配置Hibernate XML s的不會被複制到瓶子裏。任何一個讓我知道問題出在哪裏可以存在
您正在運行哪個目標? – thekbb 2014-12-08 06:16:43
xml文件存儲在哪裏?您的''目標將它們從'bin'複製到'dist',但'bin'被''目標清空,所以我無法知道xml文件如何放入'bin'。 –
2014-12-11 18:16:32
你的「jar」目標從「$ {build.dir}」中創建jar。您的copy-hbm應該將hbm文件從其源文件複製到{build.dir}。在調試主體之前,請測試各個目標。另外,jar目標(在你的情況下)必須依賴於「copy-hbm」。 – Jayan 2014-12-12 05:09:13