首页 > 解决方案 > Java War 文件不会在 Eclipse 中使用 WildFly 更新

问题描述

我在 Windows 7 64 位上使用 Eclipse 版本 2019-03 (4.11.0) 和 Wildfly 16。我已经在 Eclipse 中将我的 Java Web 项目转换为 Maven 项目。通过向导进行的初始配置和部署有效,但现在每当我更改我的代码并尝试重新部署时,我都看不到更新的代码。到目前为止我所尝试的(我实际上不确定如何进行重新部署,并假设以下一项或多项组合会强制重新部署):

  1. 更新项目(Alt + F5 并右键单击项目 --> Maven --> 更新项目)
  2. mvn clean
  3. mvn install
  4. mvn clean install
  5. 更新项目,然后mvn clean install

这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>GumboChannel</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>GumboChannel</name>
  <description></description>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.2.Final</version>
</dependency>
  </dependencies>
</project>

编辑:我更新了问题以澄清我实际上不确定如何重新部署。

标签: javaeclipsemaven

解决方案


实际上,您上面列出的所有选项都不会重新部署应用程序。

  • 更新项目:修改 Eclipse 项目以从 pom.xml 中获取更改
  • mvn clean install(来自 CLI):运行 Maven(在 Eclipse 之外),清理目标目录,将所有源代码编译到目标目录,打包 .war 文件,将其安装在本地 .m2 存储库中。通常你根本不需要这个,只需从菜单中选择“自动构建”。

我想您已经在 Eclipse 的“服务器”视图中配置了 Wildfly。如果您想重新部署,您应该在该视图中找到某种“重新启动”和/或“重新部署”命令。


推荐阅读