Eclipse将.war文件放在哪里?

5
我是Java EE网络开发的新手。我在Eclipse中创建了一个基于JAX-RS的Web应用程序,并在Tomcat上运行。该项目由Maven管理依赖项。一切都正常工作。但是,现在如果我要发布这个项目,我会假设我需要向用户提供一个.war文件。
那么这就是我的问题:
1. Eclipse将war文件放在哪里? 2. 这个文件是否包含了所有正确顺序运行为Web应用程序所需的内容,还是我需要额外提供其他文件,例如web.xml或pom.xml? 3. 如果应用程序的用户已经下载了Tomcat,他/她只需要将.war文件复制到Tomcat目录中并右键单击运行吗?
5个回答

3
  1. Eclipse将WAR文件部署到Tomcat中,具体位置取决于您的Tomcat设置。详情请参见此处。您提到了一个pom.xml文件,所以您可能使用了一些maven插件(比如这里),用于构建war文件。请参考插件文档了解如何配置war文件的创建。

  2. 一切都在项目内(在您的情况下,项目已经正确地在maven中进行了配置)。您只需将其部署到服务器即可。

  3. 您不应该右键单击或其他操作。只需将其放置到Tomcat安装的webapps文件夹中或通过管理器应用程序进行部署。我想您应该在这里阅读文档,了解什么是部署以及如何进行部署。

另一个有用的链接:http://www.codejava.net/ides/eclipse/eclipse-create-deployable-war-file-for-java-web-application


2

在项目中右键单击 > 导出 > web 项目 > .war,然后将 .war 文件复制到您的 Apache Tomcat 的 webapp 目录中。


1
如果您使用Maven并已正确配置,则创建war文件的最简单方法是调用以下命令: $ mvn clean install
在项目目录中(即pom.xml所在位置),之后您将在以下位置找到生成的war文件: path_to_your_project/targe/your_application.war

0
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.0.1-SNAPSHOT\I4Connect-0.0.1-SNAPSHOT.war

In the fore mentioned folder 
(C:\Users\username\\.m2\repository\com\i4\I4Connect\0.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.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.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

0

Eclipse本身不会将任何东西放在任何地方。当您使用Maven构建项目时,根据Maven文件夹结构,它将在目标目录中构建并放置WAR文件,该目录位于文件系统中的项目所在位置(通常在您的工作区内),您可以在Eclipse包/项目资源管理器中看到。

尝试使用mvn clean package构建您的项目

如果您的POM.xml中所有依赖项的范围都为“compile”,那么Maven将把这些相应的JAR推送到web-inf / lib中,但是如果您有“provided”范围,则必须自己将这些JAR放入服务器中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接