简体   繁体   English

如何使用Ant和Ivy构建项目及其依赖项

[英]How to build a project and it's dependencies using Ant and Ivy

I have a WebApp with two dependencies as shown below. 我有一个具有两个依赖项的WebApp,如下所示。 I would like to build a war file for deployment on Tomcat using Ant + Ivy. 我想构建一个用于使用Ant + Ivy在Tomcat上部署的war文件。

+
+-MyWebApp // this Dynamic Java Web Application (deployed Tomcat and launches
           // a thread contained in MyApp) 
+-MyApp // this is just a vanilla Java Application
+-MyCommonStuff // these are common classes shared between MyApp and MyWebApp
                // Ex. Database access code & business classes

Using the Ant documentation I've worked out how to create the appropriate build.xml files for each project. 使用Ant文档,我已经研究出如何为每个项目创建适当的build.xml文件。 In other words each project has an independent build.xml, so in order to build the whole project all I have to do is: 换句话说,每个项目都有一个独立的build.xml,因此要构建整个项目,我要做的就是:

mkdir build
cd build
export SOME_COMMONBASE=`pwd`
svn co https://mybuildmachine.lan/svn/mycommonstuff mycommonstuff
cd mycommonstuff
ant
cd ..
% this produces mycommonstuff.jar
svn co https://mybuildmachine.lan/svn/myapp myapp
cd myapp
ant
cd ..
% this produces myapp.jar
svn co https://mybuildmachine.lan/svn/mywebapp mywebapp
cd mycommonstuff
ant
cd ..
% this produces mywebapp.war and deploys it to Tomcat

Now what I would like to do is bring it all together so that I can kick off a single build. 现在,我要做的就是将所有内容组合在一起,这样我就可以开始一个构建。 On the surface it looks like I should somehow be able to create an Ivy build.xml which wires the dependencies together. 从表面上看,我似乎应该能够以某种方式创建一个Ivy build.xml,它将依赖项连接在一起。 However, I've read the Ivy documentation and Googled for examples but I'm still none-the-wiser about how I can accomplish this task. 但是,我已经阅读了Ivy文档和Googled的示例,但是对于如何完成此任务,我仍然一无所知。 Can someone give me some pointers on how I can do this? 有人可以给我一些指导我该怎么做吗?

What you want to do is to use Ivy's Ant tasks for the wiring. 您要做的是使用Ivy的Ant任务进行布线。 There's quite a lot of finer details in there but basically you need your own Ivy repository and then just publish your own project artifacts there to use them elsewhere. 那里有很多更好的细节,但基本上,您需要自己的Ivy存储库,然后在此处发布自己的项目工件以在其他地方使用它们。

For JAR library projects: 对于JAR库项目:

  • Use ivy:retrieve to get the dependencies so that you can build the project into a library. 使用ivy:retrieve获取依赖项,以便可以将项目构建到库中。
  • Use ivy:publish to publish the built JAR into your own Ivy repository. 使用ivy:publish将构建的JAR发布到您自己的Ivy存储库中。

For WAR projects: 对于WAR项目:

  • Once again, use ivy:retrieve to get the dependencies so that you can build the project into a WAR. 再次使用ivy:retrieve获取依赖项,以便可以将项目构建到WAR中。

As for other parts, Ant itself has many many tasks to help you and then there's some tasks provided by others such as svn task by tigris for getting the source from SVN and Ant's optional SCP task for transferring the WAR file to extenral server. 至于其他部分,Ant本身有许多任务可以为您提供帮助,然后其他人提供了一些任务,例如tigris的svn任务(用于从SVN获取源代码)和Ant的可选SCP任务(用于将WAR文件传输到外部服务器)。

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

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