【问题标题】:Maven doesn't copy empty directories to webapps folder while creating war fileMaven在创建war文件时不会将空目录复制到webapps文件夹
【发布时间】:2017-01-01 09:27:12
【问题描述】:

我有他遵循 maven web 应用程序的结构

当我执行mvn install 命令时,它正在创建war 文件,但是如果您查看target directory/sureportal,您可以很容易地看到webapps 目录中的许多子文件夹丢失了。怎么了?

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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.nokia</groupId>
  <artifactId>sureportal</artifactId>
  <packaging>war</packaging>
  <version>1.0.0</version>
  <name>sureportal Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>sureportal</finalName>
  </build>
</project>

【问题讨论】:

    标签: java maven


    【解决方案1】:

    尝试运行mvn clean install。这将首先清除您编译的文件,并确保所有文件都是从头开始编译的。请查看此线程以获取更多详细信息how-is-mvn-clean-install-different-from-mvn-install

    祝你好运。

    【讨论】:

      【解决方案2】:

      除了 sbaitmangalkar 的回答之外,将 maven-war-plugin 插入到您的 POM 的构建部分:

      <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-war-plugin</artifactId>
                  <version>2.6</version>
                  <configuration>
                      <!-  if you don't have a web.xml, otherwise "true" -->
                      <failOnMissingWebXml>false</failOnMissingWebXml>
                      <includeEmptyDirectories>true</includeEmptyDirectories>
                      <includes>**/*</includes>
      
                      <!-- if want your web files to be filterd -->
                      <webResources>
                          <resource>
                              <directory>src/main/webapp</directory>
                              <includes>
                                  <include>**/*</include>
                              </includes>
                              <filtering>true</filtering>
                          </resource>
                          <resource>
                              <directory>src/main/resources/META-INF</directory>
      
                              <!-- only if needed in your project -->
                              <targetPath>/META-INF</targetPath>
                              <includes>
                                  <include>context.xml</include>
                              </includes>
                              <filtering>true</filtering>
                          </resource>
                      </webResources>
      
                  </configuration>
              </plugin>
          </plugins>
      </build>
      

      这会明确地告诉构建过程要做什么。

      【讨论】:

      • 默认情况下不需要。
      • @SaifAsif 你说的话听起来很正确。但如果没有这部分,在我的项目中存在与 Subodh Joshi 报告的相同问题
      • 如果创建war时没有复制的文件夹是空的,即使maven也会复制文件夹怎么办?
      • 是的,如果你像我在回答中那样插入&lt;includeEmptyDirectories&gt;true&lt;/includeEmptyDirectories&gt;,即使是空文件夹也会被复制
      • 好吧,你的意思是这样 -> stackoverflow.com/questions/2605747/… 但这适用于资源目录而不适用于其他
      【解决方案3】:

      您可以拥有maven-war-plugin 并配置为包含空文件夹。

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <includeEmptyDirectories>true</includeEmptyDirectories> 
        </configuration>
      </plugin>
      

      【讨论】:

      • 与我的解决方案完全相同。查看我的 POM 片段中的 cmets ......但没问题
      • @JimHawkins 很抱歉,您的代码标签有很多东西让这个答案有点笨拙。无论如何感谢您的时间和支持。
      猜你喜欢
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 2017-09-25
      相关资源
      最近更新 更多