Eclipse 将 .war 文件放在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36581546/
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
Where does Eclipse place the .war file?
提问by Zeus
I'm new to Java EE web development. I've created a JAX-RS based web application in Eclipse which I'm running on Tomcat. The project has dependencies managed by Maven. Everything is working fine. However now if I have to ship this project, I'd assume I would have to provide a .war file to the user.
我是 Java EE Web 开发的新手。我在 Eclipse 中创建了一个基于 JAX-RS 的 Web 应用程序,该应用程序在 Tomcat 上运行。该项目具有由 Maven 管理的依赖项。一切正常。但是现在如果我必须发布这个项目,我想我必须向用户提供一个 .war 文件。
So here's my questions:
所以这是我的问题:
- Where does eclipse place this war file?
- Will this file have everything in it, in the right order to run as web application or do I need to provide any other file in addition, like web.xml or pom.xml?
- If the user of the application has downloaded tomcat, does all he/she needs to do it copy the .war file into the Tomcat directory and right-click to run?
- eclipse 把这个war 文件放在哪里?
- 该文件是否包含所有内容,以正确的顺序作为 Web 应用程序运行,还是我需要另外提供任何其他文件,如 web.xml 或 pom.xml?
- 如果应用程序的用户已经下载了 tomcat,他/她是否需要将 .war 文件复制到 Tomcat 目录中并右键单击运行?
回答by Akceptor
Eclipse deploys WAR to the tomcat. Exact place depends on your tomcat settings. See details here: Where does Tomcat in Eclipse store the expanded WAR?You mentioned a pom.xml file so you probably use some maven plugin (like this https://maven.apache.org/plugins/maven-war-plugin/) to build the war file. Refer the plugin documentation to understand how to configure the war artifact creation.
Everything is inside (in your case the project is properly configured in maven). You should just deploy to the server.
You should not right click or whatever. Just place into the webapps folder in the tomcat installation or deploy via manager app. I gues you should read the documentation here https://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.htmlto understand what is deployment and how to do it.
Eclipse 将 WAR 部署到 tomcat。确切位置取决于您的 tomcat 设置。在此处查看详细信息:Eclipse 中的 Tomcat 将扩展的 WAR 存储在何处?您提到了 pom.xml 文件,因此您可能会使用一些 maven 插件(例如https://maven.apache.org/plugins/maven-war-plugin/)来构建 war 文件。请参阅插件文档以了解如何配置War工件创建。
一切都在里面(在您的情况下,项目已在 maven 中正确配置)。您应该只部署到服务器。
你不应该右键单击或其他什么。只需放入 tomcat 安装中的 webapps 文件夹或通过管理器应用程序部署即可。我想您应该阅读此处的文档https://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html以了解什么是部署以及如何进行部署。
One more useful link:http://www.codejava.net/ides/eclipse/eclipse-create-deployable-war-file-for-java-web-application
另一个有用的链接:http: //www.codejava.net/ides/eclipse/eclipse-create-deployable-war-file-for-java-web-application
回答by Grzegorz Domaga?a
If you use maven and you configured it properly the easiest way to create your war is to call:
如果您使用 maven 并正确配置了它,那么创建War的最简单方法是调用:
$ mvn clean install
$ mvn 全新安装
in your project directory, in the location of pom.xml. After that you will find generated war in: path_to_your_project/targe/your_application.war
在您的项目目录中,在 pom.xml 的位置。之后,您将在以下位置找到生成的War:path_to_your_project/targe/your_application.war
回答by miaguicam
right click in project > export > web project > .war Then copy the .war file into webapp directory of your apache tomcat.
右键单击项目 > 导出 > Web 项目 > .war 然后将 .war 文件复制到 apache tomcat 的 webapp 目录中。
回答by Tasmine Rout
Eclipse does not put anything anywhere itself. When you build the project using maven, according to maven folder structure it will build and put the war file in its target directory where the project is present in file system (mostly inside your workspace), which you can see on your eclipse package/project explorer.
Eclipse 本身不会在任何地方放置任何东西。当您使用 maven 构建项目时,它会根据 maven 文件夹结构构建并将 war 文件放置在项目存在于文件系统中的目标目录中(主要在您的工作区中),您可以在您的 eclipse 包/项目中看到探险家。
Try building your project using mvn clean package
尝试使用 mvn clean package 构建您的项目
If all your dependencies has scope 'compile' in POM.xml then maven will push those corresponding jars to web-inf/lib, but if you have 'provided' scope then you have to put those JARs in sever by yourself.
如果您的所有依赖项在 POM.xml 中都有“编译”范围,那么 maven 会将这些相应的 jar 推送到 web-inf/lib,但如果您有“提供”范围,那么您必须自己将这些 JAR 放在服务器中。
回答by Hareesh Shastry
Even I am new to J2EE Web Application development.
I am using Tomcat 8.0.27 and Eclipse Luna.
From my trial and error, I have noticed that after successful Maven Build creation (pom.XML --> Run As (4 Maven Clean OR 6 Maven Install); the war file is saved in the user folder as below.
C:\Users\username\.m2\repository\com\i4\I4Connect##代码##.0.1-SNAPSHOT\I4Connect-0.0.1-SNAPSHOT.war
In the fore mentioned folder
(C:\Users\username\.m2\repository\com\i4\I4Connect##代码##.0.1-SNAPSHOT\); I also see the following files along with the mentioned war file.
1. _remote.repositories --> Repositories file
2. I4Connect-0.0.1-SNAPSHOT.pom --> POM file
3. maven-metadata-local --> XML file
Hope this helps.
-----------------------------------------------------------------------------
Hello Again,
what i realized was, the war file created earlier was a snapshot.
However, when I closely tracked the build creation again, I noticed that eclipse provides details of every step of the build creation that could be observed in the console.
Following is snapshot of what I got when I re-created the build.
******************************************************************************
******************************************************************************
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building I4Connect Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ I4Connect ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 6 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ I4Connect ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ I4Connect ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\EclipseProjectWorkspace\iConnectDev\I4Connect\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ I4Connect ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ I4Connect ---
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ I4Connect ---
[INFO] Packaging webapp
[INFO] Assembling webapp [I4Connect] in [D:\EclipseProjectWorkspace\iConnectDev\I4Connect\target\I4Connect]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\EclipseProjectWorkspace\iConnectDev\I4Connect\src\main\webapp]
[INFO] Webapp assembled in [22881 msecs]
[INFO] Building war: ***D:\EclipseProjectWorkspace\iConnectDev\I4Connect\target\I4Connect.war***
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ I4Connect ---
[INFO] Installing D:\EclipseProjectWorkspace\iConnectDev\I4Connect\target\I4Connect.war to C:\Users\hareesh.s\.m2\repository\com\i4\I4Connect##代码##.0.1-SNAPSHOT\I4Connect-0.0.1-SNAPSHOT.war
[INFO] Installing D:\EclipseProjectWorkspace\iConnectDev\I4Connect\pom.xml to C:\Users\hareesh.s\.m2\repository\com\i4\I4Connect##代码##.0.1-SNAPSHOT\I4Connect-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 59.929 s
[INFO] Finished at: 2018-02-28T11:31:11+05:30
[INFO] Final Memory: 11M/125M
[INFO] ------------------------------------------------------------------------
******************************************************************************
******************************************************************************
As can be gathered, the war file is created in the Workspace folder.
D:\EclipseProjectWorkspace\iConnectDev\I4Connect\target\I4Connect.war