Is it possible to refer to a classpath defined in one build file from another build file?

不羁岁月 提交于 2020-01-06 07:55:17

问题


In project A's build file, there is a <path>;

In project B's build file, I want to execute a tool class in project A by <java> task.

The <java> task need to use that path in its "classpathref" property.

The <path> in project A's build file is quite complicated so that I don't want to copy it to project B's build file.

So is it possible to refer to a classpath defined in one build file from another build file?


回答1:


Using the import or include ANT tasks is the way to do this.... however, these are both designed build multi-module builds. It's generally a really bad idea to couple two different projects in this manner....

I understand the motivation, classpath management is one of the most important and error-prone parts of a Java build. My recommendation is to adopt Apache ivy and let it manage your build's 3rd party dependencies.

Example:

The ivy cachepath task to create your ANT path, using dependency declarations.

   <ivy:cachepath pathid="test.path">
        <dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="default"/>
        <dependency org="junit" name="junit" rev="4.10" conf="default"/>
    </ivy:cachepath>

The jars themselves can be locally stored or retrieved from the Maven Central repository




回答2:


Ant allows to import a project file into another. You may check section 'Resolving files against the imported file' as this will be needed in most cases.



来源:https://stackoverflow.com/questions/10944349/is-it-possible-to-refer-to-a-classpath-defined-in-one-build-file-from-another-bu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!