我有一个 小牛 项目,具有4个组件网络,持久性,常见和其他项目。

我的相关内容 pom 文件:

父母POM:

<groupId>com.test</groupId>
<artifactId>test</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<modules>
    <module>components/TestWeb</module>
    <module>components/TestOther</module>
    <module>components/TestPersistence</module>
    <module>components/TestCommon</module>
</modules>


<build>
    <defaultGoal>package</defaultGoal>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <dependentWarExcludes>
                    **/hibernate.cfg.xml,**/sql-map-config.xml,**/web.xml,WEB-INF/classes/META-INF/**
                </dependentWarExcludes>
            </configuration>
        </plugin>
     </plugins>
 </build>

普通POM:

<modelVersion>4.0.0</modelVersion>
<artifactId>test-common</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>

持久性POM:

<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-persistence</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>


<dependencies>
  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

Web POM:

<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-web</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TestWeb</name>

<parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
</parent>

  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>


  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-persistence</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>


  <dependency>
    <groupId>com.test</groupId>
    <artifactId>test-other</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>

也许我在副本和粘贴中打破了一些东西,但是XML是有效的。

  • 当我运行MVN软件包时,该项目 战争档案 并非创建,但所有组件软件包都是创建和完善的。
  • 如果,我跑了 mvn war:war, ,战争文件是空的。

如何解决这个问题?

有帮助吗?

解决方案

在根项目中使用插件不起作用。您可以在此处配置插件

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

但是,仍必须在子标题中引用它们以进行活动(除了是默认过程的一部分,例如Maven-Compiler-Plugin和Maven-Resource-Plugin)。

因此,要么您将战争拼写配置移至 pluginManagement 在根项目中,包括

<build>
    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1</version>
        <execution>
            <goals>...</goals>
        </execution>
    </plugin>
</build>

在您的战争项目中,或者您将整个配置转移到战争中。

其他注意:确保根POM中模块的顺序与项目之间的依赖关系一致(在您的情况下,只需扭转顺序)。

其他提示

我创建了类似的项目结构,并粘贴了您提供的POM,但无法再现问题。跑步 mvn package 从汇总的POM可以按预期工作:

$ mvn package 
[INFO] Scanning for projects...
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Unnamed - com.test:test:pom:0.0.1-SNAPSHOT ............ SUCCESS [5.819s]
[INFO] Unnamed - com.test:test-common:jar:0.0.1-SNAPSHOT ..... SUCCESS [3.343s]
[INFO] Unnamed - com.test:test-persistence:jar:0.0.1-SNAPSHOT  SUCCESS [0.136s]
[INFO] Unnamed - com.test:test-other:jar:0.0.1-SNAPSHOT ...... SUCCESS [0.079s]
[INFO] Unnamed - com.test:test-web:war:0.0.1-SNAPSHOT ........ SUCCESS [1.899s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

并产生以下结果:

$ tree .
.
├── components
│   ├── TestCommon
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-common-0.0.1-SNAPSHOT.jar
│   ├── TestOther
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-other-0.0.1-SNAPSHOT.jar
│   ├── TestPersistence
│   │   ├── pom.xml
│   │   ├── ...
│   │   └── target
│   │       ├── maven-archiver
│   │       │   └── pom.properties
│   │       └── test-persistence-0.0.1-SNAPSHOT.jar
│   └── TestWeb
│       ├── pom.xml
│       ├── src
│       │   └── main
│       │       └── webapp
│       │           ├── index.jsp
│       │           └── WEB-INF
│       │               └── web.xml
│       └── target
│           ├── maven-archiver
│           │   └── pom.properties
│           ├── test-web-0.0.1-SNAPSHOT
│           │   ├── index.jsp
│           │   ├── META-INF
│           │   └── WEB-INF
│           │       ├── classes
│           │       ├── lib
│           │       │   ├── test-common-0.0.1-SNAPSHOT.jar
│           │       │   ├── test-other-0.0.1-SNAPSHOT.jar
│           │       │   └── test-persistence-0.0.1-SNAPSHOT.jar
│           │       └── web.xml
│           └── test-web-0.0.1-SNAPSHOT.war
└── pom.xml

因此,您的问题必须与您的战争项目本身,其结构或类似的东西有关。运行时请显示其结构和Maven的输出 war:war 在上面。


顺便说一句,这是POM在多模型构建中通常应该看起来像:

<project>
  <modelVersion>4.0.0</modelVersion>
  <!--groupId>com.test</groupId--> <!-- unnecessary, you inherit it -->
  <artifactId>test-web</artifactId>
  <packaging>war</packaging>
  <!--version>0.0.1-SNAPSHOT</version--> <!-- unnecessary, you inherit it -->
  <parent>
    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <relativePath>../../pom.xml</relativePath>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId> <!-- DRY, use built-in properties -->
      <artifactId>test-common</artifactId>
      <version>${project.version}</version> <!-- DRY, use built-in properties -->
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-persistence</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>test-other</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</project>

另一件事,来自父项目的战争插件配置 继承(您可以通过运行检查 help:effective-pom 在Web模块中),但是在Web模块本身中配置它是很有意义的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top