いくつかの外部 jar を使用する Java プロジェクトから jar ファイルを作成しようとしました。lib フォルダーを作成し、そこに必要なすべての jar を配置しました。
libフォルダー内のすべてのjarをビルドパスに追加して、Eclipseでプロジェクトを実行すると、正常に動作します。
build.xml から ant で jar を作成しようとすると、問題ないようで、エラーは表示されません。
jar を実行しようとすると、「無効または破損した jarfile」というメッセージが表示されます。
build.xml で: コンパイルに使用するパスを定義します。
<path id="project.classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</path>
これがコンパイルのターゲットです。
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath refid="project.classpath"/>
</javac>
</target>
そして、これはjarファイルを作成するためのターゲットです:
<target name="dist" depends="compile" description="generate the distribution" >
<mkdir dir="${dist}"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/MyProject-${DSTAMP}.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="${main}" />
<attribute name="Class-Path:" value="lib/**/*.*"/>
</manifest>
<fileset dir="${src}" includes="images/**/*.*" />
</jar>
<echo file="${dist}/start.bat" message="java -jar MyProject-${DSTAMP}.jar" />
</target>
私が間違ったことを教えてください。