2016-08-25 43 views
2

我有他下一個Maven Web應用程序的結構Maven不包括空目錄複製到web應用文件夾在創建war文件

enter image description here

當我執行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> 

回答

2

您可以有一個maven-war-plugin並配置爲包含空文件夾。

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

是的,它的作品感謝您的答案。 –

+0

與我的解決方案完全相同。看到我的POM片段中的評論...但沒有問題 – JimHawkins

+0

@JimHawkins對不起,你的代碼標籤有很多東西,使這個答案有點笨拙,具體回答。任何感謝您的時間和支持。 –

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> 

這告訴構建過程做什麼明確。

+1

這不應該是默認情況下需要的。 –

+0

@SaifAs你說的話聽起來很合適。但是沒有這個部分,在我的項目中存在與Subodh Joshi – JimHawkins

+0

報告相同的問題如果在創建戰爭時未複製的文件夾是空的,那麼maven會複製這些文件夾呢? –

相關問題