Ant覆盖自定义清单文件 [英] Ant overwritting custom manifest file

查看:132
本文介绍了Ant覆盖自定义清单文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ant创建一个也使用自定义清单文件的jar。 build.xml文件正确构建一切。但是,当我检查jar中的清单文件时,我的属性不在。它看起来被替换为由Ant构建的默认MANIFEST.MF文件。我的构建文件如下:

 <?xml version =1.0?> 

 < property name =srclocation =src/> 
< property name =buildlocation =build/>
< property name =distlocation =dist/>

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

< target name =maindepends =compile,dist,build>
< echo>
构建.jar文件。
< / echo>
< / target>

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

< target name =compiledepends =build>
< javac srcdir =$ {src}destdir =$ {build}/>
< / target>

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

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

< / target>



我需要改变什么指定自定义清单而不是默认的Ant MANIFEST.MF文件?

解决方案

我相信jar ant任务有一个清单属性您可以在其中指定要使用的实际文件。在这种情况下,您可以使用清单任务引用您创建的文件。



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

 < ; target name =distdepends =compile> 

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

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

< jar manifest =$ {build} /META-INF/MANIFEST.MFjarfile =$ {dist} /lib/MyGame.jarbasedir =$ {build}/ >

< / target>


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?

解决方案

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>

这篇关于Ant覆盖自定义清单文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆