在Eclipse中,我使用ant创建.jar文件
我需要调试另一个项目中的jar。我怎么能生成一个jar也包含源代码调试?
编辑:我使用以下命令创建jar:
<jar destfile="${my.lib}/${myProject}.jar" basedir="${eclipse.workspace}/${myProject}/bin">
在jar 中包含源文件,这就足够了:
<jar destfile="${my.lib}/${myProject}.jar" basedir="${eclipse.workspace}/${myProject}" includes="bin/**,src/**"/>
然而,你在你的问题中提到了create an executable jar
,为此,这应该工作:
<target name="abc">
...
<manifest file = "MANIFEST.MF">
<attribute name = "Main-Class" value = "yourClassName"/>
<attribute name = "Class-Path" value = "."/>
</manifest>
<jar destfile="${my.lib}/${myProject}.jar" basedir="${eclipse.workspace}/${myProject}" includes="bin/**,src/**" manifest="MANIFEST.MF"/>
</target>
使用Apache Ant
任务zipgroupfileset
创建一个可运行的jar文件
<manifest file = "MANIFEST.MF"> <!-- Manifest-Version: 1.0 -->
<attribute name = "Main-Class" value = "${RunnableMain-Class}"/>
<attribute name = "Class-Path" value = "."/>
</manifest>
<jar destfile="${exportDestination}/${jarFileName}.jar" basedir="${class-files}"
manifest="MANIFEST.MF">
<fileset dir="${class-files}" includes="**/*.class" />
<zipgroupfileset dir="${buildPath-Libraries}" includes="**/*.jar" />
</jar>
完整长度示例:
<property name="exportDestination" value="${basedir}"/>
<property name="ProjectName" value="${basedir}/MyRunnableJAR"/>
<property name="jarFileName" value="myRunnableJAR"/>
<property name="RunnableMain-Class" value="org.openqa.grid.selenium.GridLauncher"/>
<property name="class-files" value="${ProjectName}/bin" />
<property name="buildPath-Libraries" value="${ProjectName}/lib"/>
<property name="source-dir" value="${ProjectName}/src" />
<property name="Ant-Version" value="Apache Ant 1.8.2"/>
<property name="Built-By" value="Yashwanth.Merugu"/>
<path id="buildLibraries"> <!-- http://ant.apache.org/manual/using.html#path -->
<fileset dir="${buildPath-Libraries}">
<include name="*.jar"/>
</fileset>
</path>
<!-- compile -->
<target name="compile" >
<mkdir dir="${class-files}"/>
<javac srcdir="${source-dir}" destdir="${class-files}" includeantruntime="false" encoding="iso-8859-1">
<classpath refid="buildLibraries"/>
</javac>
</target>
<!-- jar -->
<target name="jar" depends="compile">
<manifest file = "MANIFEST.MF"> <!-- Manifest-Version: 1.0 -->
<attribute name = "Built-By" value = "${Built-By}"/>
<attribute name = "Ant-Version" value = "${Ant-Version}"/>
<attribute name = "Main-Class" value = "${RunnableMain-Class}"/>
<attribute name = "Class-Path" value = "."/>
</manifest>
<jar destfile="${exportDestination}/${jarFileName}.jar" basedir="${class-files}" manifest="MANIFEST.MF">
<fileset dir="${class-files}" includes="**/*.class" />
<zipgroupfileset dir="${buildPath-Libraries}" includes="**/*.jar" />
</jar>
</target>
从Eclipse创建Runnable JAR File