ANT -将字符串转换为带有location属性的路径



我有以下ANT脚本,它在运行时基于websphere根目录为我提供了websphere库的列表。我需要将结果字符串转换为单独的路径位置元素

我当前的脚本是

<?xml version="1.0" encoding="UTF-8"?>
<project name="TestPath" basedir="." default="print-dirset">
    <target name="init" description="Define websphere libraries">
        <property name="compile.lib.dir" value="C:SoftwareWAS85" />
    </target>
    <target name="print-dirset" depends="init" description="">
        <path id="websphere.libs">
            <dirset dir="${compile.lib.dir}">
                <include name="*" />
            </dirset>
        </path>
        <property name="websphere.libs.list" refid="websphere.libs" />
        <echo message="websphere.libs.list: ${websphere.libs.list}" />
        <pathconvert property="websphere.libs.convert" pathsep="${file.separator}*${path.separator}">
            <path path="${websphere.libs.list}" />
        </pathconvert>
        <echo message="websphere.libs.convert: ${websphere.libs.convert}" />
    </target>
</project>

输出如下所示的字符串

 [echo] websphere.libs.list: C:SoftwareWAS85Scheduler;C:SoftwareWAS85UDDIReg;C:SoftwareWAS85bin;C:SoftwareWAS85configuration;....C:SoftwareWAS85web;C:SoftwareWAS85wlp
 [echo] websphere.libs.convert: C:SoftwareWAS85Scheduler*;C:SoftwareWAS85UDDIReg*;C:SoftwareWAS85bin*;C:SoftwareWAS85configuration*;...C:SoftwareWAS85web*;C:SoftwareWAS85wlp

我想把上面的第二个字符串转换成如下的结构

<path id="websphere.classpath">
    <pathelement location="C:SoftwareWAS85Scheduler*" />
    <pathelement location="C:SoftwareWAS85UDDIReg*" />
    <pathelement location="C:SoftwareWAS85bin*" />
    <pathelement location="C:SoftwareWAS85configuration*" />
......
    <pathelement location="C:SoftwareWAS85web*" />
    <pathelement location="C:SoftwareWAS85wlp*" />
</path>

转换中的最后一个元素还需要添加'*'部分,该部分不在原始字符串中。

可以和

这样的结构一起使用
<path id="compile.classpath">
  <path refid="ext.classpath"/>
  <path refid="websphere.classpath"/>
  <path refid="module.compile.classpath"/>
</path>

上述尝试的目的是通过使用JDK 1.6提供的通配符类路径来减少类路径的长度,该通配符类路径在ANT 1.8.2开始的ANT中可用。我正在使用ANT 1.8.4。

我不是ANT方面的专家,我看一些例子就能过得去。

有办法实现我想要做的吗?我该怎么做呢?任何例子都会很有帮助。

如果您的所有依赖项都驻留在C:SoftwareWAS85中,您可以使用filesset来捕获您的所有依赖项:

<fileset dir="${compile.lib.dir}" id="compile.files">
  <include name="**/*.java"/>
  <!-- include name="**/*.jar" /-->
</fileset>

您可以在build.xml的其他地方使用compile.files来引用此文件集

通过在javac任务中使用fork="yes"和executable="path-to-my-executable"属性,我能够让通配符部分工作。

我不想标记问题已回答,因为我的基本问题是关于转换字符串。但是由于收到的答案没有谈到这一点,也没有提到如何让通配符类路径工作,我的问题的目的是让通配符类路径工作,我在这里注意到,无论谁试图让它工作

我仍然需要一些帮助来将分号分隔的字符串转换成下面的

<path id="websphere.classpath">
    <pathelement location="C:SoftwareWAS85Scheduler*" />
    <pathelement location="C:SoftwareWAS85UDDIReg*" />
    <pathelement location="C:SoftwareWAS85bin*" />
    <pathelement location="C:SoftwareWAS85configuration*" />
......
    <pathelement location="C:SoftwareWAS85web*" />
    <pathelement location="C:SoftwareWAS85wlp*" />
</path>

更新:

我编写了一个自定义ANT任务来获得通配符类路径

最新更新