抽取依赖jar包的类并打包Shade
比如:将名称为abc的java项目打成jar包abc.jar,该项目依赖bbc.jar的com.bbc.ClassBbc,打包时com.bbc.ClassBbc会被抽取到abc.jar里面。
配置如下:
项目pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.abc.main.Tester</mainClass> <!-- 主类 -->
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
将JAR包部署到Maven私服上
项目pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- 构建管理:仓库的地址 -->
<distributionManagement>
<repository>
<id>my-deploy-release</id>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>my-deploy-snapshot</id>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
maven-settings.xml:
<servers>
<server>
<id>my-deploy-release</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>my-deploy-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>