Maven WAR file directory structure is incorrect

Answered

The war file created by Teamcity Maven build isn't correct. There are duplicate web.xml and all root files are under classes. I'm new to maven and teamcity. Can someone point out what went wrong here?


[root@hostname ~]# unzip LoginDemo-1.0.0.17.war -d LoginDemo-1.0.0.17
[root@hostname ~]# tree LoginDemo-1.0.0.17


LoginDemo-1.0.0.17
├── META-INF
│   ├── MANIFEST.MF
│   └── maven
│   └── LoginDemo
│   └── LoginDemo
│   ├── pom.properties
│   └── pom.xml
└── WEB-INF
├── classes
│   ├── error.html
│   ├── login.html
│   ├── logout.jsp
│   ├── META-INF
│   │   └── MANIFEST.MF
│   ├── securePage1.jsp
│   ├── securePage2.jsp
│   └── WEB-INF
│   └── web.xml
└── web.xml


My Source directory structure is

[root@hostname src]# tree /opt/teamcity/work/a1335cb631475bf4/src/main/webapp/
/opt/teamcity/work/a1335cb631475bf4/src/main/webapp/


├── error.html
├── login.html
├── logout.jsp
├── META-INF
│   └── MANIFEST.MF
├── securePage1.jsp
├── securePage2.jsp
└── WEB-INF
└── web.xml

My Teamcity Build configuration looks like this.

General Settings:

 

Build Steps:

 


Pom.xml looks like the following:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>LoginDemo</groupId>
  <artifactId>LoginDemo</artifactId>
  <version>1.0.0.17</version>
  <packaging>war</packaging>
  <name>Login Demo</name>
  <description>Login Demo Java Project</description>
  <build>
      <resources>
          <resource>
          <directory>src/main/webapp</directory>
          </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.3</version>
              <configuration>
              <warSourceDirectory>WebContent</warSourceDirectory>
              <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
              </configuration>
          </plugin>
      </plugins>
  </build>
</project>

1 comment
Comment actions Permalink

Fixed it. warSourceDirectory should have been src/main/webapp and then I also deleted the resources part (I think its for other external stuff that needs to be included). Now the War file structure is correct.

Here is the updated 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>LoginDemo</groupId>
  <artifactId>LoginDemo</artifactId>
  <version>1.0.0.17</version>
  <packaging>war</packaging>
  <name>Login Demo</name>
  <description>Login Demo Java Project</description>
  <build>
      <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.3</version>
              <configuration>
              <warSourceDirectory>src/main/webapp</warSourceDirectory>
              <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
              </configuration>
          </plugin>
      </plugins>
  </build>
</project>

0

Please sign in to leave a comment.