Ant overwritting custom manifest file

☆樱花仙子☆ 提交于 2019-12-10 04:22:27

问题


I am creating a jar with Ant that also uses a custom manifest file. The build.xml file builds everything properly. However, when I check the manifest file in the jar, my properties are not there. It looks like it is being replaced with the default MANIFEST.MF file built by Ant. My build file is below:

<?xml version="1.0" ?>

<property name="src" location="src" />
<property name="build" location="build" />
<property name="dist" location="dist" />

<target name="clean">
    <delete dir="${build}" />
    <delete dir="${dist}" />
</target>

<target name="main" depends="compile, dist, build">
    <echo>
        Building the .jar file.
    </echo>
</target>

<target name="build">
    <mkdir dir="${build}" />
    <mkdir dir="${build}/META-INF" />
</target>

<target name="compile" depends="build">
    <javac srcdir="${src}" destdir="${build}"/>
</target>

<target name="dist" depends="compile">
    <mkdir dir="${dist}/lib" />
    <manifest file="${build}/META-INF/MANIFEST.MF">
        <attribute name="Class-Path" value="MyGame.jar" />
        <attribute name="Main-Class" value="game.Game"/>    
    </manifest>

    <jar jarfile="${dist}/lib/MyGame.jar" basedir="${build}" />

</target>

What do I have to change to specify the custom manifest instead of the default Ant MANIFEST.MF file?


回答1:


I believe the jar ant task has a manifest attribute where you can specify the actual file to use. In this case you'd reference the file you created with the manifest task

http://ant.apache.org/manual/Tasks/jar.html

<target name="dist" depends="compile">

    <mkdir dir="${dist}/lib" />

    <manifest file="${build}/META-INF/MANIFEST.MF">
        <attribute name="Class-Path" value="MyGame.jar" />
        <attribute name="Main-Class" value="game.Game"/>  
    </manifest>

    <jar manifest="${build}/META-INF/MANIFEST.MF" jarfile="${dist}/lib/MyGame.jar" basedir="${build}" />

</target>


来源:https://stackoverflow.com/questions/10202447/ant-overwritting-custom-manifest-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!