我是Java EE Web开发的新手。我在Eclipse中创建了一个基于JAX-RS的Web应用程序,我在Tomcat上运行。该项目具有由Maven管理的依赖项。一切都很好。但是现在如果我必须发布这个项目,我假设我必须向用户提供.war文件。
所以这是我的问题:
答案 0 :(得分:2)
Eclipse将WAR部署到tomcat。确切的地方取决于您的tomcat设置。请在此处查看详细信息:Where does Tomcat in Eclipse store the expanded 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,以了解什么是部署以及如何进行。
另一个有用的链接:http://www.codejava.net/ides/eclipse/eclipse-create-deployable-war-file-for-java-web-application
答案 1 :(得分:0)
如果你使用maven并且你正确配置它,最简单的方法就是打电话:
$ mvn clean install
在项目目录中,位于pom.xml的位置。 之后你会发现生成的战争: path_to_your_project / targe / your_application.war
答案 2 :(得分:0)
Eclipse不会在任何地方放置任何东西。使用maven构建项目时,根据maven文件夹结构,它将构建war文件并将其放在文件系统中存在项目的目标目录中(大多数位于工作区内),您可以在eclipse包/项目中看到资源管理器。
尝试使用mvn clean package
构建项目如果所有依赖项都在POM.xml中具有“compile”范围,那么maven会将相应的jar推送到web-inf / lib,但是如果你已经“提供”了范围,那么你必须自己将这些JAR放入服务器中。
答案 3 :(得分: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
答案 4 :(得分:-1)
右键点击项目>出口> web项目> 。战争 然后将.war文件复制到apache tomcat的webapp目录中。