简体   繁体   中英

Maven WAR file directory structure is incorrect - Teamcity

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?

Here is the war file structure:

[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:

Teamcity 常规设置

Build Steps:

Teamcity 构建步骤

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>

Fixed it. warSourceDirectory should have been src/main/webapp and then I also deleted the resources (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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM