背景

有一个项目不是web项目,不能使用 war 插件. 需要把所有依赖的 jar 包下载到lib目录,然后通过 cli 的方式启动执行 . 类试于 arthas 的启动方式.

详情

Maven添加 plugin

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-assembly-plugin</artifactId>
  4. <version>3.1.0</version>
  5. <configuration>
  6. <descriptors>
  7. <descriptor>src/assembly/distribution.xml</descriptor>
  8. </descriptors>
  9. <outputDirectory>
  10. ${project.build.directory}
  11. </outputDirectory>
  12. <appendAssemblyId>false</appendAssemblyId>
  13. </configuration>
  14. <executions>
  15. <execution>
  16. <id>create-distribution</id>
  17. <phase>package</phase>
  18. <goals>
  19. <goal>single</goal>
  20. </goals>
  21. </execution>
  22. </executions>
  23. </plugin>

指定打包方式

  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  3. <id>test-agent-assembly</id>
  4. <formats>
  5. <format>zip</format>
  6. </formats>
  7. <includeBaseDirectory>false</includeBaseDirectory>
  8. <fileSets>
  9. <fileSet>
  10. <directory>${basedir}/src/main/resources</directory>
  11. <outputDirectory>./</outputDirectory>
  12. </fileSet>
  13. </fileSets>
  14. <dependencySets>
  15. <!--核心依赖jar包,打包到core目录下-->
  16. <dependencySet>
  17. <includes>
  18. <include>top.mybatis.code:generator</include>
  19. </includes>
  20. <outputDirectory>lib</outputDirectory>
  21. <useProjectArtifact>false</useProjectArtifact>
  22. <useTransitiveFiltering>true</useTransitiveFiltering>
  23. </dependencySet>
  24. <!--公共lib目录-->
  25. </dependencySets>
  26. </assembly>

实际结果

image.png

Maven Deploy 命令行

Deploy jar包

  1. mvn deploy:deploy-file -DgroupId=com.qumoon -DartifactId=qumoon-job-queue -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=qumoon-job-queue-1.0-SNAPSHOT.jar -Durl=http://xxx.xxx.xxx:8082/repository/maven-snapshots/ -DrepositoryId=xxxxxx

Deploy jar包带pom文件

  1. mvn deploy:deploy-file -DgroupId=com.qumoon -DartifactId=qumoon-job-queue -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=qumoon-job-queue-1.0-SNAPSHOT.jar -Durl=http://xxx.xxx.xxx:8082/repository/maven-snapshots/ -DrepositoryId=xxxxxx -DpomFile=qumoon-job-queue-1.0-SNAPSHOT.pom

Deploy pom文件

  1. mvn deploy:deploy-file -DgroupId=com.xxxx.express -DartifactId=quicloud-express-taobao-api-gateway-parent -Dversion=1.0-SNAPSHOT -Dpackaging=pom -Durl=http://xxxx.xxx.xxxx:8082/repository/maven-snapshots/ -DrepositoryId=xxxxx -Dfile=quicloud-express-taobao-api-gateway-parent-1.0-SNAPSHOT.pom