【问题标题】:Maven WAR file directory structure is incorrect - TeamcityMaven WAR 文件目录结构不正确 - Teamcity
【发布时间】:2023-03-10 06:08:01
【问题描述】:

Teamcity Maven 构建创建的战争文件不正确。有重复的 web.xml 并且所有根文件都在类下。我是 Maven 和 teamcity 的新手。有人能指出这里出了什么问题吗?

这是war文件结构:

[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

我的源目录结构是

[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

我的 Teamcity Build 配置如下所示。

常规设置:

构建步骤:

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

【问题讨论】:

    标签: java maven tomcat continuous-integration teamcity


    【解决方案1】:

    修复它。 warSourceDirectory 应该是 src/main/webapp 然后我还删除了 resources (我认为它用于需要包含的其他外部内容)。现在 War 文件结构是正确的。

    这是更新后的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多