私の驚いたことに、Java用Eclipse(Neon)によって生成されたbuild.xml
ファイルには、jar
タスクの呼び出しを含む要素がありません。多くの場合、コード生成では、コード生成を完全に再生成または回避できるように、コードを使用して編集する必要があると思います。生成されたファイルのコメントは、インポートによって機能を拡張することによって編集を避けることができる可能性があることを示唆しています。Eclipseの生成されたantスクリプトとjarファイルを作成する方法はありますか?
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
私はexport.xml
と呼ばれる第二のファイルに<?eclipse.ant.import?>
要素を使用することができるだろうと思いました。 ant
のスクリプトでは、1つのビルドファイルにつき1つのプロジェクトが想定されているので、最初のプロジェクトのターゲットに依存する2番目のプロジェクトがあります。
build.xml
を再生成すると、期待通りに「インポート」が含まれていることがわかります。
<import file="export.xml"/>
残念ながら、これは動作しません。コマンドラインから実行するant
を実行すると、エクスポート/ jar
プロジェクトが無視されるように見えます。
(7行にネストされた)import要素で生成されたスクリプト...
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="ohana1">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<import file="export.xml"/>
<path id="ohana1.classpath">
<pathelement location="bin"/>
<pathelement location="../export/ohana1/commons-collections-3.2.1.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="ohana1.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
</project>
export.xml
ファイルは、Eclipseことjar
...
<?eclipse.ant.import?>
<project basedir="." default="export" name="ohana1Export">
<target depends="build,make-jar" name="export"/>
<target name="make-jar">
<jar destfile="../export/ohana1/${ant.project.name}.jar" basedir="bin"/>
</target>
</project>
ノートを作るためのものこのプロジェクト/ビルドファイルには依存ファイルであるbuild
という名前のターゲットが存在しないため、Antエディタはこのexport.xml
ファイルについて不平を言います。 build
ターゲットはbuild.xml
に生成されています。そのエラーは「ダム」エディターからのものであるため、ant
の実行を先に進めました。コマンドラインからant
を呼び出すと、jar
ファイルが作成されていないことがわかりました。
.jar
ファイルをエクスポートする必要があり、人間がすべての要件を満たすant
スクリプトを維持する必要がある場合、Eclipseのant
スクリプトジェネレータは役に立たないと結論してください。