【问题标题】:Adding .class files onto ant classpath for groovc ant task compilation?将 .class 文件添加到 ant 类路径中以进行 groovy ant 任务编译?
【发布时间】:2012-05-02 13:36:40
【问题描述】:

我在 Eclipse 中有一个名为 MyApp 的项目。我有另一个名为 TestRepository 的项目,其中包含为 MyApp 项目编写的测试用例。

我正在尝试编译测试用例并使用类路径为的 groovyc ant 任务生成 junit 报告:

<path id="classpath">
   <fileset dir="lib/MyApp">
      <include name="*.jar" />
   </fileset>   
</path>

MyApp 的 jar 文件被添加到类路径中。如果在测试用例中引用的 MyApp 项目的类在 lib 文件夹的 jars 中不存在,我希望 groovyc 搜索 MyApp/bin 包中的类。

我该怎么做?

PS:MyApp 项目非常庞大,我不想让 groovyc 任务编译 MyApp 中的所有 src 文件,而只是从 bin 中提取额外的 .class 文件并将其放在其类路径中。

【问题讨论】:

    标签: ant fileset


    【解决方案1】:

    Java、Groovy 或任何其他 JVM 语言中的类路径是一个路径列表,每个路径都可以是目录或 JAR 文件。您已添加代码所依赖的所有 JAR 文件,但未添加 bin 目录。

    如下所示添加一个路径元素,将 bin 目录添加到您的类路径中。请记住,需要给出相对于构建脚本位置的路径。

    <path id="classpath">
       <fileset dir="lib/MyApp">
          <include name="*.jar" />
       </fileset>
       <pathelement path="bin" />
    </path>
    

    上述路径定义假定“bin”与您的构建脚本位于同一目录中。如果不是,请相应调整路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      相关资源
      最近更新 更多