說我有一個圖書館和一個二元目標的相關性,我們姑且稱之爲MyLib
和MyBin
, MyBin
取決於MyLib
。使用Ant構建當前構建目標
我正在嘗試創建一個MyBin
的Ant構建文件,它首先構建MyLib
,然後在構建MyBin
時將其包含在類路徑中。
我試過使用Ant任務,如Building other, dependent projects with Ant。
但是,它不工作,從ant -v
我認爲MyBin
build-deps
目標是甚至沒有建設MyLib
。看起來很混亂MyBin
和MyLib
屬性?我不知道如何防止這個。
我只在下面傾倒MyBin/build.xml
,但MyLib
幾乎完全相同,只是它沒有build-deps
目標。
<project name="MyBin" default="main" basedir=".">
<property name="projectName" value="MyBin" />
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
<property name="dist.dir" location="dist" />
<property name="dist.lib.dir" location="dist/lib" />
<property name="lib.dir" value="lib" />
<target name="build-deps" depends="init">
<!-- MyLib main target does clean -> build -> jar to dist folder -->
<!-- Its build.xml uses many of the same property values as above -->
<ant antfile="../MyLib/build.xml" target="main"/>
</target>
<path id="classpath">
<fileset dir="${basedir}/">
<include name="../MyLib/dist/**/*.jar" />
</fileset>
</path>
<!-- Need classpath to run this -->
<target name="compile" depends="build-deps" description="compile the source ">
<javac includeantruntime="false" srcdir="${src.dir}"
destdir="${build.dir}" classpathref="classpath" />
</target>
<!-- Group all dependencies into a big dependency-all.jar -->
<target name="copy-dependencies">
<mkdir dir="${dist.lib.dir}" />
<jar jarfile="${dist.lib.dir}/dependencies-all.jar">
<zipgroupfileset dir="${lib.dir}">
<include name="**/*.jar" />
</zipgroupfileset>
</jar>
</target>
<!-- jar it, extract above dependency-all.jar and zip it with project files -->
<target name="jar" depends="compile, copy-dependencies"
description="package, output to JAR">
<mkdir dir="${dist.dir}" />
<mkdir dir="${dist.lib.dir}" />
<jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
</manifest>
<zipfileset src="${dist.lib.dir}/dependencies-all.jar"
excludes="META-INF/*.SF" />
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Default, run this -->
<target name="main" depends="clean, compile, jar" />
</project>
我ant -v in MyBin
看到的是沿着線的東西:
build-deps:
Project base dir set to: /MyBin
[ant] calling target(s) [main] in build file /MyLib/build.xml
parsing buildfile /MyLib/build.xml with URI = file:/MyLib/build.xml
Project base dir set to: /MyBin
Override ignored for property "projectName"
Override ignored for property "build.dir"
Override ignored for property "dist.dir"
Override ignored for property "dist.lib.dir"
Override ignored for property "lib.dir"
[pathconvert] Set property classpath.name =
[ant] Entering /MyLib/build.xml...
Build sequence for target(s) `main' is [clean, init, copy-dependencies, jar, main]
Complete build sequence is [clean, init, copy-dependencies, jar, main, ]
clean:
[delete] Deleting directory /MyBin/bin
[delete] Deleting directory /MyBin/bin
init:
[mkdir] Created dir: /MyBin/bin
copy-dependencies:
[ant] Exiting /MyLib/build.xml.
現在我收到了一條不同的錯誤消息,而且它很明顯是配置爲遵循'MyLib'中的'MyBin/build.xml' ant任務,因爲錯誤消息來自於不能從'MyBin/build.xml'中找到* only *的目錄(我試過明確指定'antfile'以及'dir')。 我想要一個密封的'MyLib' ant build,接着是一個'MyBin'(然後將'MyLib'輸入到classpath中)。我認爲你已經指出了我的正確方向,但會花費一些時間處理各種螞蟻任務選項並報告回來。 –
是的,'inheritAll = false1似乎能夠強制'MyLib'構建密碼。 –