eclipse 将eclipse项目.classpath依赖解压到ant脚本中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6517977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:31:37  来源:igfitidea点击:

Extract eclipse project .classpath dependencies into ant script

eclipseantjavac

提问by Nick

I have a list of Eclipse projects that I would like to compile based on the existing project configuration.

我有一个 Eclipse 项目列表,我想根据现有项目配置对其进行编译。

As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and perform a "javac" compilation in the right order. This would save time in describing the same dependencies again in the ant script or a Makefile.

据我所知,如果 ant 脚本可以读取 .classpath 文件,它几乎可以推断出项目依赖项并以正确的顺序执行“javac”编译。这将节省在 ant 脚本或 Makefile 中再次描述相同依赖项的时间。

The dependencies I am interested in are JAR Dependencies, JRE dependencies, and inter-project dependencies. These are -- as far as I can tell -- part of the .classpath XML file.

我感兴趣的依赖是 JAR 依赖、JRE 依赖和项目间依赖。据我所知,这些是 .classpath XML 文件的一部分。

Any ideas on how Eclipse project dependencies could used in an ant script?

关于如何在 ant 脚本中使用 Eclipse 项目依赖项的任何想法?

回答by FlorianOver

Right click on your Project -> Export "General/Ant Buildfiles". Choose the projects and there you go.

右键单击您的项目 -> 导出“General/Ant Buildfiles”。选择项目,然后就可以了。

Otherwise... I have some experience with ant4eclipse and it is a hassle to get it stable.

否则...我对 ant4eclipse 有一些经验,要让它稳定起来很麻烦。

Go check Buckminster or Maven Tycho for a good solution.

去检查 Buckminster 或 Maven Tycho 以获得一个好的解决方案。

回答by Pat B

I'm currently using Ivy along with Ant, Eclipse and Maven.

我目前正在使用 Ivy 以及 Ant、Eclipse 和 Maven。

I just love the way Ivy works.

我只是喜欢 Ivy 的工作方式。

Currently, we have a workspace with many projects using Liferay (with Tomcat) for the front-end and Glassfish for the back-end.

目前,我们有一个工作区,其中包含许多项目,前端使用 Liferay(使用 Tomcat),后端使用 Glassfish。

We were looking for a way to manage our dependencies a lot better than how we were doing it.

我们正在寻找一种方法来管理我们的依赖项,而不是我们的做法。

So I took Ivy, replaced all of the classpaths and deployment dependencies in eclipse and was able to build my application using 1 ivy file per project using either Eclipse or Ant. Ivy integrates like a charm in ant and builds are done either from the workspace or by command line.

因此,我采用了 Ivy,替换了 eclipse 中的所有类路径和部署依赖项,并且能够使用 Eclipse 或 Ant 为每个项目使用 1 个 ivy 文件构建我的应用程序。Ivy 像 ant 中的魅力一样集成,并且构建是从工作区或通过命令行完成的。

I strongly suggest you look at this avenue. Additionnaly, by adding Artifactory, we have a local repository in which the ivy files look for dependencies. This helps us maintain and rule which jars are to be used by developpers. Once everything is setup, we will build our application nightly using Jenkins and these builds will be using our Artifactory repository to resolve dependencies since our build servers do not have access to the internet.

我强烈建议你看看这条大道。此外,通过添加 Artifactory,我们有一个本地存储库,常春藤文件在其中查找依赖项。这有助于我们维护和规则开发人员要使用哪些 jar。一切设置好后,我们将每晚使用 Jenkins 构建我们的应用程序,这些构建将使用我们的 Artifactory 存储库来解决依赖关系,因为我们的构建服务器无法访问互联网。

Hope this helped

希望这有帮助

回答by flavio.donze

If you are running the Ant script only from eclipse using the "External Tools Configurations", you can add the variable ${project_classpath} to the Classpath.

如果您仅使用“外部工具配置”从 Eclipse 运行 Ant 脚本,则可以将变量 ${project_classpath} 添加到类路径。

Depending on if you are in a plugin project and dependencies you might need to add the ${eclipse_home}.

根据您是否在插件项目和依赖项中,您可能需要添加 ${eclipse_home}。

In case you get an error launching Variable references empty selection: ${project_classpath}, make sure the ant xml file or at least the project is selected. This is important.

如果您在启动时遇到错误Variable references empty selection: ${project_classpath},请确保选择了 ant xml 文件或至少选择了项目。这个很重要。

回答by sudocode

I believe the ant4eclipseproject provides support for executing Ant builds based on Eclipse metadata files.

我相信ant4eclipse项目支持基于 Eclipse 元数据文件执行 Ant 构建。

However, in my opinion that is doing things back to front. You shouldn't have your build (Ant) depending on your IDE (Eclipse) environment. But it is useful if you can derive your Eclipse environment from your Ant build.

然而,在我看来,这就是把事情搞反了。您不应该根据您的 IDE (Eclipse) 环境来构建 (Ant)。但是,如果您可以从您的 Ant 构建中派生出您的 Eclipse 环境,这将非常有用。

This is an approach used successfully in a team I worked in. We had a helper Ant target which applied XLST to project build.xmlfiles to transform these into Eclipse .classpathfiles. Thus the Ant build.xmlfiles were the single configuration point for our projects.

这是一种在我工作的团队中成功使用的方法。我们有一个帮助 Ant 目标,它应用 XLST 到项目build.xml文件以将这些文件转换为 Eclipse.classpath文件。因此,Antbuild.xml文件是我们项目的单一配置点。