【问题标题】:Where does Eclipse place the .war file?Eclipse 将 .war 文件放在哪里?
【发布时间】:2016-04-12 18:44:31
【问题描述】:

我是 Java EE Web 开发的新手。我在 Eclipse 中创建了一个基于 JAX-RS 的 Web 应用程序,它在 Tomcat 上运行。该项目具有由 Maven 管理的依赖项。一切正常。但是现在如果我必须发布这个项目,我会假设我必须向用户提供一个 .war 文件。

这是我的问题:

  1. eclipse 将这个 war 文件放在哪里?
  2. 此文件中是否包含所有内容,以正确的顺序作为 Web 应用程序运行,或者我是否需要另外提供任何其他文件,例如 web.xml 或 pom.xml?
  3. 如果应用程序的用户已经下载了tomcat,是否只需将.war文件复制到Tomcat目录中,然后右键运行?

【问题讨论】:

  • 请否决你的论点。

标签: java eclipse maven jersey


【解决方案1】:
  1. 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 文件。请参阅插件文档以了解如何配置战争工件创建。

  2. 一切都在里面(在您的情况下,项目已在 maven 中正确配置)。您应该只部署到服务器。

  3. 你不应该右键单击或其他任何东西。只需放入 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

【讨论】:

    【解决方案2】:

    在项目中单击鼠标右键 > 导出 > Web 项目 > .war 然后将 .war 文件复制到 apache tomcat 的 webapp 目录中。

    【讨论】:

      【解决方案3】:

      如果您使用 maven 并且正确配置了它,那么创建战争的最简单方法是调用:

      $ mvn 全新安装

      在您的项目目录中,在 pom.xml 的位置。 之后,您将在以下位置找到生成的战争: path_to_your_project/targe/your_application.war

      【讨论】:

        【解决方案4】:

        Eclipse 本身不会在任何地方放置任何东西。当您使用 maven 构建项目时,根据 maven 文件夹结构,它将构建并将 war 文件放在项目在文件系统中存在的目标目录中(主要在您的工作区中),您可以在 eclipse 包/项目中看到探险家。

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

        如果您的所有依赖项在 POM.xml 中都具有“编译”范围,那么 maven 会将这些相应的 jar 推送到 web-inf/lib,但如果您有“提供”范围,那么您必须自己将这些 JAR 放入服务器中。

        【讨论】:

          【解决方案5】:
          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
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-01-02
            • 2013-05-04
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多