简体   繁体   English

在蚂蚁脚本中模块化类路径(例如通过refid)

[英]Modularizing classpaths in ant scripts (e.g. via refid)

Since my ant file is quite complex, I want to modularize my classpath-elements. 由于我的ant文件非常复杂,因此我想对我的classpath-elements进行模块化。

Currently, I use refid in the following way: 目前,我以以下方式使用refid

<path id="compile.classpath">
  <pathelement path="foo"/>
  <!-- ... -->
</path>

<path id="test.classpath">
  <path refid="compile.classpath"/>
  <pathelement path="bar"/>
  <!-- ... -->
</path>

<!-- ... -->

    <javac>
        <classpath refid="compile.classpath"/>
    </javac>

    <junit>
        <!-- ... -->
        <classpath>
             <path refid="test.classpath"/>
             <path path="bazz"/>
        </classpath>
    </junit>

<!-- ... -->

Is this a sensible approach? 这是明智的做法吗? Or is there a better one? 还是有更好的选择?

Is it ok to use a path-id ( compile.classpath ) for a classpath-refid (in <javac> )? 将path-id( compile.classpath )用作classpath-refid(在<javac> )是否可以? (It currently works, but refid does require the elements to be of the same type. Since path and classpath are both path-like structures, are they of the same type?) (它当前有效,但是refid确实要求元素的类型相同。由于pathclasspath都是类似路径的结构,因此它们是否属于同一类型?)

I successfully used this approach at a previous job and it was really the only way I could keep everything sane. 我在上一份工作中成功使用了这种方法,这实际上是使一切保持理智的唯一方法。

I eventually took things a step further an put all my third-party library definitions in a separate ext-libs.xml file since several of them were multi-jar libraries and making sure I had all of them contained in my final war files was getting to be a giant hassle. 最终,我进一步迈出了一步,将我所有的第三方库定义放到了一个单独的ext-libs.xml文件中,因为它们中的几个是多jar库,并确保我将所有这些库都包含在最终的war文件中成为一个巨大的麻烦。 That way, in my main build.xml (and others) I could refer to, say, lib.jaxb and not have to worry that I'd updated the version numbers in the files names everywhere. 这样,在我的主build.xml (和其他文件)中,我可以引用lib.jaxb ,而不必担心我会更新所有文件名中的版本号。

You've already figured out the trick of extending your compile classpath to make your test classpath, so you're on the right track. 您已经想出了扩展编译类路径以生成测试类路径的技巧,因此您处于正确的轨道上。

In short, press on. 简而言之,按。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM