我有一个父 maven 模块runtime
,它包含webApp
存储网络相关内容的目录。(html、js 等...)。在我的子模块employee
中也遵循相同的结构。所以当我构建具有依赖项的子项目 jar 时,它包含两者webapp
内容相互覆盖。我的要求是从我的孩子(员工)jar 中排除父 webapp 目录和依赖项。我使用Maven Shade 插件将 jar 与依赖项捆绑在一起。请让我知道如何实现这一点。
父 pom 文件(运行时)
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sample.myproject</groupId>
<artifactId>base</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>runtime</artifactId>
<name>Runtime Engine</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
//dependencies goes here
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/config</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources>
//plugins goes here (maven-jar-plugin)
</build>
</project>
儿童绒球(员工)
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sample.myproject</groupId>
<artifactId>base</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>employee</artifactId>
<name>Employee Engine</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
//dependencies goes here
<dependency>
<groupId>com.sample.myproject</groupId>
<artifactId>runtime</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/config</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources>
//plugins goes here (maven-jar-plugin)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.sample.myproject.employee.AppStarter</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/LICENSE</exclude>
<exclude>LICENSE</exclude>
</excludes>
</filter>
</filters>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</build>
</project>