Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ant清单路径条目从依赖项JAR的路径构建_Java_Ant_Ant Contrib - Fatal编程技术网

Java 使用ant清单路径条目从依赖项JAR的路径构建

Java 使用ant清单路径条目从依赖项JAR的路径构建,java,ant,ant-contrib,Java,Ant,Ant Contrib,我的问题是,我必须从如下路径构建清单条目类路径 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"> <seque

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

  • 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>

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

我还看到您正在使用ivy,那么为什么不使用它的任务将依赖项jar放置在相对于您正在构建的jar的本地目录中呢。否则,您的jar将被硬编码,以期望其依赖项是在您的机器上工作的绝对路径,但不是非常可移植的

下面是一个小片段:

  <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>



不理解您的要求,但似乎您只需要从绝对文件路径获取文件名?!为此有一项任务。另外,当使用\1时,您的regexp应该有一个组,f.e.+\(.jar)意味着\1将从C:\Users\rosansamuel.ivy2\cache\log4j\log4j\log4j\jars\log4j-1.2.14.jarHi捕获log4j-1.2.jar,是的,您是正确的。我的要求是从路径中单独提取jar名称。但我有路径列表。