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

发布于 2024-08-22 01:11:52 字数 1106 浏览 7 评论 0原文

我有一个具有两个依赖项的 WebApp,如下所示。我想使用 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

使用 Ant 文档,我已经弄清楚如何为每个项目创建适当的 build.xml 文件。 换句话说,每个项目都有一个独立的 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

现在我想做的是将它们放在一起,以便我可以启动单个构建。从表面上看,我应该能够以某种方式创建一个 Ivy build.xml,将依赖项连接在一起。然而,我已经阅读了 Ivy 文档并在 Google 上搜索了示例,但我仍然不知道如何完成这项任务。 有人可以给我一些关于如何做到这一点的指示吗?

I have a WebApp with two dependencies as shown below. I would like to build a war file for deployment on Tomcat using Ant + Ivy.

+
+-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.
In other words each project has an independent build.xml, so in order to build the whole project all I have to do is:

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. 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.
Can someone give me some pointers on how I can do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2024-08-29 01:11:52

你想要做的是使用 Ivy 的 Ant 任务 进行连接。那里有很多更详细的细节,但基本上你需要自己的 Ivy 存储库,然后在那里发布你自己的项目工件以在其他地方使用它们。

对于 JAR 库项目:

  • 使用 ivy:retrieve 获取依赖项,以便您可以将项目构建到库中。
  • 使用 ivy:publish 将构建的 JAR 发布到您自己的 JAR 中常春藤存储库。

对于 WAR 项目:

  • 再次使用 ivy :retrieve 获取依赖项,以便您可以将项目构建为 WAR。

至于其他部分,Ant 本身有很多任务可以帮助您,还有其他人提供的一些任务,例如 tigris 的 svn 任务,用于从 SVN 和 Ant 获取源代码可选的 SCP 任务,用于将 WAR 文件传输到外部服务器。

What you want to do is to use Ivy's Ant tasks for the wiring. 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.

For JAR library projects:

  • Use ivy:retrieve to get the dependencies so that you can build the project into a library.
  • Use ivy:publish to publish the built JAR into your own Ivy repository.

For WAR projects:

  • Once again, use ivy:retrieve to get the dependencies so that you can build the project into a 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文