eclipse 用ant搭建eclipse项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5530653/
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
Build eclipse project with ant
提问by DodoFXP
I am developing JSR 268 compliant portlet and utility with eclipse. Now, the utility is designed to be a separate JAR from the portlet itself.
我正在使用 Eclipse 开发符合 JSR 268 的 portlet 和实用程序。现在,该实用程序被设计为独立于 portlet 本身的 JAR。
Does anyone now how to write an ant build.xml that will 1. Compile and JAR my utility class 2. Move the JAR to the ./lib folder of the portlet 3. Compile and maybe even delpoy the portlet to a tomcat running on localhost?
有没有人现在如何编写一个 ant build.xml,它将 1. 编译和 JAR 我的实用程序类 2. 将 JAR 移动到 portlet 的 ./lib 文件夹 3. 编译甚至可能将 portlet delpoy 到在本地主机上运行的 tomcat ?
My biggest problem right now are the build-time dependencies. I dont want to hardcode all the folders as I share this project with two other developers which are on another platform. Is it possible to reuse the buildpath from eclipse?
我现在最大的问题是构建时依赖。当我与另一个平台上的其他两个开发人员共享这个项目时,我不想对所有文件夹进行硬编码。是否可以重用 eclipse 的构建路径?
Thank you in advance, Felipe
提前谢谢你,费利佩
回答by Michael Spector
Does this wizard help
这个向导有帮助吗
Rigth-click on project -> Export ... -> Ant buildfiles.
?
?
回答by Tobber
Though you probably have figured something out by now, for future references I would suggest taking a look at Eclipse's ability to use Ant files as project builders.
尽管您现在可能已经想通了一些东西,但为了将来参考,我建议您查看 Eclipse 使用 Ant 文件作为项目构建器的能力。
An advantage of this is, that will happen automatically as you build and since you only pack and copy the jar file, you don't have to worry about changes in e.g. the class paths, as you would in the two previous answers
这样做的一个优点是,这会在您构建时自动发生,并且由于您只打包和复制 jar 文件,因此您不必像在前两个答案中那样担心类路径的更改
- Create a ant file that jar the utility project. Follow: [1]
- Add it as a ant-builder to your utility project as described in [1]
- Now Eclipse will automatically generate the jar file every time you build.
- Extend the ant script to also copy to jar file to the lib dir.
- Eclipse have ant task to convert workspace/project relative paths to normal file paths. See [2]. Note that for those tasks to work, you must select ''Run is the same JRE as the workspace'' under the ''JRE'' tab when configuring the ant builder
- In order to ensure your utility is build first add a project reference from your portlet to your utility project
right click > properties > project references
- 创建一个 ant 文件来 jar 实用程序项目。关注:[1]
- 如 [1] 中所述,将其作为 ant-builder 添加到您的实用程序项目中
- 现在 Eclipse 会在每次构建时自动生成 jar 文件。
- 扩展 ant 脚本以将 jar 文件也复制到 lib 目录。
- Eclipse 具有将工作区/项目相对路径转换为普通文件路径的 ant 任务。见[2]。请注意,要使这些任务起作用,您必须在配置 ant 构建器时在“JRE”选项卡下选择“运行与工作区相同的 JRE”
- 为了确保您的实用程序被构建,首先从您的 portlet 添加一个项目引用到您的实用程序项目
right click > properties > project references
When you build the following will now happen:
当您构建时,现在将发生以下情况:
- You utility project will build first, because of the project reference
- The ant-builder will pack the jar, and copy it to the lib folder.
- You portlet project will build using the new jar.
- 由于项目引用,您的实用程序项目将首先构建
- ant-builder 将打包 jar,并将其复制到 lib 文件夹。
- 您的 portlet 项目将使用新的 jar 来构建。
回答by davidfmatheson
For 1. Just use the and Ant tasks
对于 1. 只需使用 和 Ant 任务
For 2. Is it on a remote server? How do you get it there? Windows share?
对于 2. 是否在远程服务器上?你怎么把它弄到那里?Windows 共享?
For 3. Set up the Tomcat manager and then use Tomcat's deploy/undeploy Ant tasks: http://blog.techstacks.com/2009/05/tomcat-management-setting-up-tomcat.html
3.设置Tomcat管理器,然后使用Tomcat的deploy/undeploy Ant任务:http: //blog.techstacks.com/2009/05/tomcat-management-setting-up-tomcat.html
<taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
<taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />
If you want to avoid hard-coding paths, try to use relative paths. Where are you dependencies right now? What do you feel you may have to specify an absolute path for?
如果您想避免硬编码路径,请尝试使用相对路径。你现在在哪里依赖?您觉得您可能必须为什么指定绝对路径?
回答by Surej
In Eclipse, Goto Window->preference->Ant->Runtime->Classpath->ant HomeThen add what are the thing u need to add,atlast click ok button to create ant file.
在 Eclipse 中, 转到 Window->preference->Ant->Runtime->Classpath->ant Home然后添加你需要添加的东西,最后点击 ok 按钮创建 ant 文件。