部署团队要求我们将我们的maven站点打包为战争并将其发布到Archiva存储库中。
我们的第一个问题,如何组装战争,以及里面的儿童网站。
我试试这个,但它没有用。 生成的战争不包括儿童网站。 我研究maven文档,google,stackoverflow等等。我找不到任何东西。
项目结构文件夹:
.
├── child-yyyy-1
│ ├── pom.xml
│ └── src
│ ├── main
│ │ └── java
│ │ └── com
│ │ └── xxx
│ │ └── App.java
│ └── test
│ └── java
├── child-yyyy-2
│ ├── pom.xml
│ └── src
│ ├── main
│ │ └── java
│ │ └── com
│ │ └── xxx
│ │ └── App.java
│ └── test
│ └── java
└── parent-site
├── assembly
│ └── api-site.xml
└── pom.xml
父母:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx</groupId>
<artifactId>parent-yyyy</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-yyyy</name>
<modules>
<module>../child-yyyy-1</module>
<module>../child-yyyy-2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly/api-site.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
API-site.xml中
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>api-site</id>
<formats>
<format>war</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>target/site</directory>
</fileSet>
<fileSet>
<outputDirectory>/child-yyyy-1/</outputDirectory>
<directory>child-yyyy-1/target/site</directory>
</fileSet>
<fileSet>
<outputDirectory>/child-yyyy-2/</outputDirectory>
<directory>child-yyyy-2/target/site</directory>
</fileSet>
</fileSets>
</assembly>
孩子1 pom:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xxx</groupId>
<artifactId>parent-yyyy</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../site</relativePath>
</parent>
<groupId>com.xxx</groupId>
<artifactId>child-yyyy-1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>child-yyyy-1</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
child 2 pom:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xxx</groupId>
<artifactId>parent-yyyy</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../site</relativePath>
</parent>
<groupId>com.xxx</groupId>
<artifactId>child-yyyy-2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>child-yyyy-2</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
答案 0 :(得分:1)
首先,你有一个错误的项目结构,这意味着你的父母在子文件夹中...更好的是让父母这样。
+-- parent (pom.xml)
+--- child1 (pom.xml)
+--- child2 (pom.xml)
....
这将简化您的父级,您不需要为模块提供../
...并且在子级中您不需要在父级中提供relativePath元素。
除了在父级中定义maven-assembly-plugin之外没有意义,因为父级将首先被执行,这意味着那时你还没有生成站点。
此默认解决方案是创建单独的子项
+-- parent (pom.xml)
+--- child1 (pom.xml)
+--- child2 (pom.xml)
+--- site-child (pom.xml)
像您一样定义maven-assembly-plugin,非常重要为您想要包含的网站的子项定义依赖项。
以上所有内容均使用以下内容生成:
mvn site
这意味着您处于站点生命周期中,这意味着您需要在站点生命周期中打包战争,而不是在默认生命周期中,您需要更改maven-assembly-plugin的配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly/api-site.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
以下内容:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly/api-site.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>site</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
之后应该可以通过以下方式创建:
mvn site