在 Eclipse 中构建 Java 后如何自动导出 WAR?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/347698/
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-08-11 13:41:39  来源:igfitidea点击:

How do I automatically export a WAR after Java build in Eclipse?

javaeclipsedeploymentwar

提问by Simon

I have a J2EE project in Eclipse 3.2 and at the end of every build I want to automatically create and deploy a WAR file. At the moment I have to do this by hand which is 5 or 6 mouse-cliks and it would be nice to automate it.

我在 Eclipse 3.2 中有一个 J2EE 项目,在每次构建结束时,我想自动创建和部署一个 WAR 文件。目前,我必须手动执行此操作,即 5 或 6 次鼠标点击,并且自动化它会很好。

I know I can do this with a custom build script using ANT but I am hoping for an Eclipse native solution.

我知道我可以使用 ANT 使用自定义构建脚本来做到这一点,但我希望有一个 Eclipse 本机解决方案。

I have the J2EE standard tools (JST) and Web Standard Tools (WST) plug-ins installed in my Eclipse environment.

我在 Eclipse 环境中安装了 J2EE 标准工具 (JST) 和 Web 标准工具 (WST) 插件。

采纳答案by Bananeweizen

If you can implement it as an Ant script, then you can have Eclipse invoke that Ant script on each build automatically (and inside the Eclipse environment). Use Project->Properties->Builders->Add->Ant Builder. Give that builder you custom Ant script and it will automatically be executed after the "normal" builders of your project.

如果您可以将其实现为 Ant 脚本,那么您可以让 Eclipse 在每次构建时(以及在 Eclipse 环境中)自动调用该 Ant 脚本。使用 Project->Properties->Builders->Add->Ant Builder。为该构建器提供自定义 Ant 脚本,它将在项目的“普通”构建器之后自动执行。

回答by Loki

There are only two options:

只有两种选择:

  • Or you right click on project: Run -> Run on server. (Your project needs to be a web project.)
  • Or you write that ant script and use eclipse to store you ant run configuration and reuse that config.
  • 或者您右键单击项目:运行 -> 在服务器上运行。(您的项目需要是一个网络项目。)
  • 或者您编写该 ant 脚本并使用 eclipse 来存储您的 ant 运行配置并重用该配置。

回答by Bananeweizen

Right click on your project: Export -> Web -> WAR File Do what you want to do.

右击你的项目:Export -> Web -> WAR File 做你想做的。

回答by Karl

Consider using netbeans, full ear and war deployment is possible without the need to write ant yourself for most of the major servers, ie tomcat, was, weblogic, glassfish and jboss.

考虑使用netbeans,可以不用自己为大部分主流服务器编写ant,例如tomcat、was、weblogic、glassfish和jboss,就可以进行fullear和war部署。

I highly recommend it, even over the IBM rational suite.

我强烈推荐它,甚至超过 IBM 理性套件。

Karl

卡尔

回答by TJR

Using the latest Eclipse Java EE release you could define Servers and attach project to those servers.

使用最新的 Eclipse Java EE 版本,您可以定义服务器并将项目附加到这些服务器。

This will automatically deploy your project to the server when the project changes.

这将在项目更改时自动将您的项目部署到服务器。