我需要 Eclipse 来部署我的 ANT 脚本构建的 WAR 文件,而不是它内部构建的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4260884/
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
I need Eclipse to deploy the WAR file my ANT script builds, not what it builds internally
提问by Gordon
I'm using Eclipse Helios. I have a dynamic web project going and I've set up Eclipse to use an Ant Builder to generate a WAR file. This all works fine; if I change a .java file, Eclipse automatically runs my build.xml via Ant and updates my WAR. If I deploy the WAR to an external instance of Tomcat, it works perfectly.
我正在使用 Eclipse Helios。我有一个动态 web 项目,我已经设置了 Eclipse 以使用 Ant Builder 生成一个 WAR 文件。这一切正常;如果我更改 .java 文件,Eclipse 会通过 Ant 自动运行我的 build.xml 并更新我的 WAR。如果我将 WAR 部署到 Tomcat 的外部实例,它会完美运行。
However, when I tell Eclipse to run my project under Tomcat, it is not using the WAR file generated by the Ant build, or using my Ant script to generate a temporary WAR.
但是,当我告诉 Eclipse 在 Tomcat 下运行我的项目时,它没有使用 Ant 构建生成的 WAR 文件,也没有使用我的 Ant 脚本生成临时 WAR。
I know this because my build.xml script includes some additional XML configuration files in WEB-INF/classes in the WAR that are not ending up in the WEB-INF/classes dir that Eclipse pushes out.
我知道这一点是因为我的 build.xml 脚本在 WAR 的 WEB-INF/classes 中包含了一些额外的 XML 配置文件,这些文件没有出现在 Eclipse 推出的 WEB-INF/classes 目录中。
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
我似乎在 Eclipse 中找不到任何说“发布时,使用此 WAR 文件而不是构建自己的文件”的内容。
An alternate approach would be to tell Tomcat when it is building a WAR to do so by adding a list of files, but I can't seem to find a way to do that either.
另一种方法是通过添加文件列表来告诉 Tomcat 在构建 WAR 时这样做,但我似乎也找不到这样做的方法。
I'm also curious how Eclipse knows what to publish since it is obviously ignoring my build.xml and my previously-generated WAR file.
我也很好奇 Eclipse 如何知道要发布什么,因为它显然忽略了我的 build.xml 和我以前生成的 WAR 文件。
回答by Scott Stanchfield
Eclipse deploys a web application by looking at the Web Deployment Assembly options for your project. You can see this by right-clicking the project, choosing Properties, and then click on Deployment Assembly. Eclipse usually uses an expanded directory deployment here rather than creating and deploying a WAR (this is based on the server plugin being used, but I think most of them use an expanded directory structure for speed). If you export as a WAR it will create a WAR with the same content.
Eclipse 通过查看项目的 Web 部署程序集选项来部署 Web 应用程序。您可以通过右键单击项目,选择“属性”,然后单击“部署程序集”来查看这一点。Eclipse 通常在这里使用扩展目录部署,而不是创建和部署 WAR(这是基于正在使用的服务器插件,但我认为它们中的大多数使用扩展目录结构以提高速度)。如果您导出为 WAR,它将创建一个具有相同内容的 WAR。
There are two main choices to do what you'd like:
有两个主要选择可以做你想做的事:
Modify the Web Deployment Assembly options to match exactly what you would like in the deployed app
Don't use Eclipse's deployment; add an "External Ant Builder" to the "Builders" options for your project (right-click project, choose Properties->Builders). You can then select which targets in the ant file you want to use when eclipse builds the project. One of these options can be a deployment step
修改 Web 部署程序集选项以与您在部署的应用程序中想要的完全匹配
不要使用Eclipse的部署;将“External Ant Builder”添加到项目的“Builders”选项中(右键单击项目,选择“属性”->“构建器”)。然后就可以在eclipse构建项目时选择要使用ant文件中的哪些目标了。这些选项之一可以是部署步骤
回答by IanC
I can't seem to find anything within Eclipse that says "when you publish, use this WAR file instead of building your own".
我似乎在 Eclipse 中找不到任何说“发布时,使用此 WAR 文件而不是构建自己的文件”的内容。
I'm an IntelliJ user, so take this with a grain of salt. But...
我是 IntelliJ 用户,所以请谨慎对待。但...
Right-click on the Project Explorer target/foo.war, select Mark Deployable.
右键单击 Project Explorer target/foo.war,选择 Mark Deployable。
Then right-click on the foo.war file again and Run As... -> Run On Server...
然后再次右键单击 foo.war 文件并运行为... -> 在服务器上运行...
Choose the JBoss instance.
选择 JBoss 实例。
If you go to the Servers view, you'll now see your WAR file under the JBoss instance as /proj_root/target/foo.war
如果您转到 Servers 视图,您现在将在 JBoss 实例下看到您的 WAR 文件为 / proj_root/target/foo.war
Oh Eclipse, sigh...
哦,Eclipse,叹息……