从 <classpath> 生成清单类路径在蚂蚁 [英] Generate manifest class-path from &lt;classpath&gt; in Ant

查看:24
本文介绍了从 <classpath> 生成清单类路径在蚂蚁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的构建文件中,jar 目标是指清单类路径的 jar.class.path 属性.编译目标指的是project.class.path

In the build file below, the jar target refers to the jar.class.path property for the manifest class-path. The compile target refers to project.class.path

这里有冗余,因为jar.class.path和project.class.path非常相似.添加库时,它们都必须更新,如果库列表很长,这可能会很痛苦.有没有更好的办法?任何解决方案都必须是跨平台的,并且始终使用相对路径.

There is redundancy here, because jar.class.path and project.class.path are very similar. They must be both updated when libraries are added, which can be a pain if the list of libraries gets very long. Is there a better way? Any solution must be cross-platform and always use relative paths.


它应该从文件集生成 JAR 类路径,而不是相反,所以我可以使用通配符来例如将所有 JAR 文件包含在一个目录中.


It should generate the JAR classpath from a fileset and not the other way around, so I can use wildcards to e.g. include all JAR files in a directory.

<?xml version="1.0"?>
<project name="Higgins" default="jar" basedir=".">

    <property name="jar.class.path" value="lib/forms-1.2.0.jar lib/BrowserLauncher.jar"/>

    <path id="project.class.path">
      <pathelement location="build"/>
      <fileset dir="lib">
        <include name="forms-1.2.0.jar"/>
        <include name="BrowserLauncher.jar"/>
      </fileset>
    </path>

    <target name="prepare">
        <mkdir dir="build"/>
    </target>

    <target name="compile" depends="prepare" description="Compile core sources">
        <javac srcdir="src"
               includes="**"
               destdir="build"
               debug="true"
               source="1.5">
          <classpath refid="project.class.path"/>
        </javac>
    </target>

    <target name="jar" depends="compile" description="Generates executable jar file">
        <jar jarfile="higgins.jar">
            <manifest>
                <attribute name="Main-Class" value="nl.helixsoft.higgins.Main"/>
                <attribute name="Class-Path" value="${jar.class.path}"/>
            </manifest>
            <fileset dir="build" includes="**/*.class"/>            
            <fileset dir="src" includes="**/*.properties"/>         
        </jar>
    </target>

</project>

推荐答案

假设 Ant 1.7 或更高版本,您可以使用 manifestclasspath 任务.

Assuming Ant 1.7 or above, you can use the manifestclasspath task.

<path id="dep.runtime">
    <fileset dir="./lib">
        <include name="**/*.jar" />
    </fileset>
</path>
<property name="dep_cp" value="${toString:dep.runtime}" />

<target name="default">
    <manifestclasspath property="manifest_cp" jarfile="myjar.jar">
        <classpath refid="dep.runtime" />
    </manifestclasspath>
    <echo message="Build Classpath: ${dep_cp}" />
    <echo message="Manifest Classpath: ${manifest_cp}" />
</target>

这篇关于从 <classpath> 生成清单类路径在蚂蚁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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