【问题标题】:Generate War file using Maven [duplicate]使用 Maven 生成 War 文件
【发布时间】:2017-11-02 00:08:21
【问题描述】:

我有一个maven pom,如下:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>MerchantWallet</groupId>
  <artifactId>StellarReceive</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>StellarReceive Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <spring.version>4.3.8.RELEASE</spring.version>
    <jdk.version>1.8</jdk.version>
</properties>

<dependencies>

      <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${spring.version}</version>
</dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
<!-- hello -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.6</version>
</dependency>


</dependencies>

<build>
    <finalName>StellarReceive</finalName>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

</project>

我在目标文件夹中没有看到 .war 文件。有人可以帮忙吗

这是我的文件夹结构:

【问题讨论】:

  • 当您run as... -> maven install 时,您是否看到任何警告或错误?
  • 请添加有关您如何运行 Maven 的更多信息。

标签: java maven tomcat


【解决方案1】:

首先你必须将你的项目定义为战争类型的包装:

<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>war</packaging>

那么编译时就需要使用maven插件生成war:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <attachClasses>true</attachClasses>
        <webXml>target/web.xml</webXml>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
</plugin>

【讨论】:

  • 有趣的旁注:如果您的 pom.xml 中缺少 &lt;packaging&gt;war&lt;/packaging&gt;,IntelliJ IDEA (v2019.2) 不会为 war 插件语法提供代码帮助
【解决方案2】:

一种解决方案就是使用 maven-war-plugin(https://maven.apache.org/plugins/maven-war-plugin/index.html)

【讨论】:

    【解决方案3】:

    尝试运行clean installclean package maven 命令。

    项目>运行方式>运行配置>左侧面板中的maven构建>右键单击>新建>目标>clean install>基本目录>选择您当前的项目工作区。>应用>运行

    clean package 或任何其他 maven 命令的方式相同。

    如果它给出BUILD SUCCESS 那么很好,否则将错误代码放在问题中。

    【讨论】:

      猜你喜欢
      • 2018-10-14
      • 1970-01-01
      • 2017-04-23
      • 2013-02-03
      • 2012-06-07
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 2014-08-16
      相关资源
      最近更新 更多