如何使用 Ant 加速 Eclipse 中的构建过程?

发布于 2024-10-31 10:16:46 字数 672 浏览 4 评论 0原文

因此,我已经到了需要加快项目构建过程的地步,因为我认为我现在的做法不太符合逻辑。我在每个项目的文件夹中都有一个 /lib 文件夹,其中包含几乎相同的 jar,并且每个 /lib 文件夹的 jar 都引用 Eclipse (3.5) 中的相应项目。 我使用 Ant 脚本来清理、构建和创建每个项目的 jar,并将 Ant 中的类路径设置为 /lib 文件夹,以便构建成功。

<property name="dir.lib" value="lib" />
<path id="classpath">
    <fileset dir="${dir.lib}" includes="*.jar" />
</path>

然后存在一个问题,即其中一个项目依赖于工作空间中的另一个项目。我已将它们链接到 Eclipse 中,但为了使用 Ant 成功构建,我需要首先单独构建项目,并将项目 jar 放在依赖它的项目的 /lib 文件夹中。所以这一切都需要相当长的时间..

我发现我在服务器上有一个 jar 存储库(但它已经过时了,而且它们没有留下任何常春藤配置),所以也许最好的办法是在构建时从服务器存储库获取 jar?然后将新创建的 jar 发布到服务器存储库上?

我应该怎么办?如何才能做到呢?

So I've come to a point when I need to speed up the build process of my projects cause the way I'm doing it now is not very logical I think. I've a /lib folder within each project's folder with basically almost the same jars and each /lib folder's jar's are referenced to appropriate project in Eclipse (3.5).
I use a Ant script to clean, build and create the jar for each project and have the class path in Ant set to the /lib folder so that the build would be successful.

<property name="dir.lib" value="lib" />
<path id="classpath">
    <fileset dir="${dir.lib}" includes="*.jar" />
</path>

Then there is a thing that one of the projects depend on another project in the work space. I've them linked in Eclipse, but to build successfully with Ant I need to first build the projects individually and place the project jars in the /lib folder of the project who depends on it. So it all takes quite time..

I see that I've a repository of jars on server (but it's outdated and they haven't left any ivy configurations) so maybe the best thing to do would be to get the jars from server repository when doing builds? And then publish the newly created jars on server repository?

What should I do? And how can it be done?

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

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

发布评论

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

评论(2

掌心的温暖 2024-11-07 10:16:46

我同意 WhiteFang32 - 使用 Maven 构建父项目和模块将使管理依赖项变得更容易。但是,如果您有很多从本地项目构建的依赖项,并且您没有(不想创建和管理)存储库,那么带有自定义目标的 ANT 是最好、最简单的解决方案。
一般来说,构建过程可以分为以下几个阶段:

  1. 清理输出目录
  2. 更新\构建依赖项
  3. 将依赖项复制到一个中心位置
  4. 编译主项目
  5. 打包主项目

下面的文章可以帮助您通过简单的方式实现上面 2 和 3 中提到的目标ANT 脚本。

祝你好运
阿维亚德

I agree with WhiteFang32 - using Maven build with parent project and modules will make managing dependencies easier. However, if you have lot of dependencies that are being built from your local projects and you do not have (do not want to create and manage) a repository then ANT with cusom targets is the best and the simpliest solution.
Generally the build process can be divided toi following stages:

  1. Clean output directories
  2. Update\build dependencies
  3. Copy dependencies into one central location
  4. Compile the main project
  5. Package the main project

The following article can help you to achieve the goals mentioned in 2 and 3 above by simple ANT scripting.
http://www.exubero.com/ant/dependencies.html

Good luck!
Aviad

£冰雨忧蓝° 2024-11-07 10:16:46

您可能需要考虑使用 Maven 进行构建和依赖项管理。 Eclipse 有一个 插件,可以更轻松地设置并无缝处理链接 jar。

如果您需要坚持使用 Ant 脚本,Ivy 仍然是一个选项,并且有自己的 Eclipse 插件。不过,您仍然需要创建配置并将项目连接在一起。您可以使用 Ant 任务将构建的 jar 放入本地存储库中。然后配置 Ivy 在查找依赖项时引用该存储库。

You might want to consider using Maven for builds and dependency management. There's a plugin for Eclipse to make it easier to setup and seamless to deal with linking jars.

If you need to stick with your Ant scripts, Ivy is still an option and has its own plugin for Eclipse. You'll still have to create the configurations though and wire the projects together. You can use the <ivy:publish> Ant task to place built jars in your local repository. Then configure Ivy to reference that repository when looking for dependencies.

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