在 Eclipse 中使用 Apache Ant 修改项目构建路径
我有一个 ant 脚本,它通常执行以下操作:clean、compile、jar、javadocs 等。我在 Eclipse 中还有 3 个项目:一个库和 2 个用于测试它的项目。
在这两个测试项目的构建路径中,我将位于库项目中的库 jar 定义为外部 jar。
库jar 在jar 名称中包含其版本,即library-0.1.jar。在 ant 脚本中,我有一个包含库版本的属性:
<property name="project_version" value="0.1"/>
因此,要更改版本,我修改此属性并再次运行脚本。正如您可能推断的那样,这会在其他 2 个项目中生成依赖项错误,因为它们仍然指向旧文件library-0.1.jar。
如何在 Eclipse 中自动更改另外 2 个项目的构建路径? Apache ant 可以使用特定标签来做到这一点吗?
谢谢。
I have an ant script that does the tipically: clean, compile, jar, javadocs, etc. I also have 3 projects in Eclipse: a library and 2 projects to test it.
In the build path of this 2 test projects I've defined as external jar the library jar located in the library project.
The library jar has its version in the jar name, i.e. library-0.1.jar. In the ant script I have a property with the version of the library:
<property name="project_version" value="0.1"/>
So to change the version I modify this property and run the script again. As you may deduce this generates a dependency error in the 2 other projects because they will still be pointing to an old file library-0.1.jar.
How can I change automatically the build path of that 2 other projects in Eclipse? Apache ant can do this with a specific tag?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在所有构建文件中引用带有变量的版本,例如
现在,当您执行构建时,您可以使用显式版本来执行以匹配您的需求,例如,
或者,您可以在每个构建脚本中加载相同的属性文件加载版本属性
请注意,如果您选择后者,您应该删除显式设置值的属性声明(从上面的帖子中)。要么先加载属性文件。
....
Refer to the version with a variable in all your build files, e.g.
Now when you execute your builds, you can execute with explict version to match what you require, e.g.
Alternatively, you could load the same properties file in each of your build scripts to load the version property
Note that if you go with the latter you should remove the property declaration (from you post above) which sets the value explicitly. Either that or load the properties file first.
....
使用 sed,例如(未测试):
Use sed, e.g. (not tested):
编辑:使用下面的方法,您将能够使用 Ant 进行编译,但是 Eclipse 会在项目资源管理器中向您显示依赖项错误,因为您没有在构建路径面板中定义任何外部 jar。要解决此问题,您必须编辑将在项目根目录中看到的 .classpath 文件并添加以下行:
其中 Library 是库项目的文件夹, bin 是类的文件夹。
已解决:
我必须为另外 2 个项目编写一个 ant 脚本,并使用该脚本设置类路径,而不是使用 eclipse IDE:
${dist} 是 jar 库所在的文件夹,如下所示: “../Library/dist”,其中 Library 是项目的名称。
${project_name} 和 ${project_version} 从 version.properties 文件加载,该文件再次存储在“../Library”中:
文件 version.properties 仅包含:
然后,在编译时添加类路径...
refid 值是之前定义的路径 id。
EDIT: Using the method below you will be able to compile using Ant, but eclipse will show you a dependency error in the project explorer because you don't have defined any external jar in the build path panel. To solve this you have to edit the .classpath file that you will see in the project root and add the following line:
Where Library is the folder for Library project and bin the folder for classes.
SOLVED:
I have to write an ant script for the 2 other projects and set the classpath with the script, not with eclipse IDE:
${dist} is the folder where is the jar library it's something like: "../Library/dist", where Library is the name of the project.
${project_name} and ${project_version} are loaded from a version.properties file that, again, is stored in "../Library":
The file version.properties just contains:
Then, to add the classpath when compiling...
The refid value is the path id defined previously.