【问题标题】:using ant manifest path entry building from path of the dependency jars使用从依赖 jar 的路径构建的 ant manifest 路径条目
【发布时间】:2013-12-13 06:30:42
【问题描述】:

我的问题是,我必须从路径构建清单条目类路径,例如

  • C:\Users\rosansamuel.ivy2\cache\log4j\log4j\jars\log4j-1.2.14.jar

你能请任何人提出一些想法吗?

下面的代码是,我正在尝试使用 propertyregex,但实际上我无法获取 jar 名称。

<for list="${ofsml.manifest.classpath.list}" delimiter=";" param="individual.path">
  <sequential>
    <property name="single.artifact.path" value="@{individual.path}"/>
    <echo message="single aritfact path name : ${single.artifact.path}"/>
    <path id="my.base.path">
      <pathelement path="${single.artifact.path}"/>
    </path>
    <property name="artifact.id.file" refid="my.base.path"/>
    <echo message=" artifact.id.file: ${artifact.id.file}"/>
    <propertyregex property="artifact.id" input="${artifact.id.file}" regexp=".*.jar" select="\1"/>
    <echo message="jar name : ${artifact.id}"/>
    <echo message="individual.path = @{individual.path}"/>
  </sequential>
</for>

【问题讨论】:

  • 不明白您的要求,但您似乎只需要从绝对文件路径获取文件名?!为此目的有一个 任务。此外,当使用 \1 您的正则表达式应该有一个组,f.e. .+\(.+jar) 表示 \1 会从 C:\Users\rosansamuel.ivy2\cache\log4j\log4j\jars\log4j-1.2.14.jar 捕获 log4j-1.2.14.jar
  • 嗨,伙计,是的,你是对的。我的要求是从路径中单独提取 jar 名称。但我有路径列表。

标签: java ant ant-contrib


【解决方案1】:

ANT 中有一个manifestclasspath 任务,可以从文件集中生成相对文件路径的列表。

我还看到您正在使用 ivy,所以为什么不使用它的 retrieve 任务将您的依赖 jar 放在相对于您正在构建的 jar 的本地目录中。否则你的 jar 将被硬编码以期望它的依赖是一个在你的机器上工作的绝对路径,但不是很便携。

这是一个小sn-p:

  <target name="build" depends="compile">
    <ivy:retrieve pattern="${dist.dir}/lib/[artifact].[ext]"/>

    <manifestclasspath property="jar.classpath" jarfile="${dist.jar}">
      <classpath>
        <fileset dir="${dist.dir}/lib" includes="*.jar"/>
      </classpath>
    </manifestclasspath>

    <jar destfile="${dist.jar}" basedir="${build.dir}/classes">
      <manifest>
        <attribute name="Main-Class" value="${dist.main.class}"/>
        <attribute name="Class-Path" value="${jar.classpath}"/>
      </manifest>
    </jar>
  </target>

更完整的例子见:

【讨论】:

    猜你喜欢
    • 2017-08-13
    • 2011-10-29
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 2013-03-31
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    相关资源
    最近更新 更多