[英]How to create an executable jar with Ant
在Eclipse中,我使用ant创建.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.