Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven doesn't copy empty directories to webapps folder while creating war file

Tags:

java

maven

I have he following structure of a maven web application

enter image description here

When I execute mvn install command it's creating war file but if you will look in target directory/sureportal you can easily see that lots of sub folders inside webapps directory are missing. What is wrong?

pom.xml file

<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>
like image 494
Subodh Joshi Avatar asked Jan 25 '26 06:01

Subodh Joshi


2 Answers

You can have a maven-war-plugin and configure to include empty folders.

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <includeEmptyDirectories>true</includeEmptyDirectories> 
  </configuration>
</plugin>
like image 183
dileep H Avatar answered Jan 26 '26 19:01

dileep H


In addition to the answer of sbaitmangalkar, insert the maven-war-plugin to the build section of your 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>

This tells the build process explicitly what to do.

like image 21
JimHawkins Avatar answered Jan 26 '26 19:01

JimHawkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!