Apache ant manifest class-path?

谁都会走 提交于 2019-11-29 04:08:39

Looking at my NetBeans-generated build file, I found this snippet in the -do-jar-with-libraries task:

<manifest>
    <attribute name="Main-Class" value="${main.class}"/>
    <attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>

So in other words, it looks like you just need to add another attribute to the manifest task that you already have.

See also the Manifest Task documentation.

Assuming the libraries do not change location from compiling to executing the jar file, you could create a path element to your classpath outside of the compile target like so:

<path id="compile.classpath">
    <fileset dir="lib" includes="**/*.jar"/>
</path>

Then you can use the created path inside your javac task in place of your current classpath.

<classpath refid="compile.classpath"/>

You can then use the path to set a manifestclasspath.

<target name="jar" depends="compile">
    <manifestclasspath property="jar.classpath" jarfile="build\jar\MyJar.jar">
      <classpath refid="compile.classpath"/>
    </manifestclasspath>    
    <jar destfile="build\jar\MyJar.jar" basedir="build\classes" >
        <manifest>
            <attribute name="Built-By" value="${user.name}" />
            <attribute name="Class-Path" value="${jar.classpath}"/>
        </manifest>
    </jar>
</target> 

The manifestclasspath generates a properly formatted classpath for use in manifest file which must be wrapped after 72 characters. Long classpaths that contain many jar files or long paths may not work correctly without using the manifestclasspath task.

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