普通Java工程可执行JAR两种打包方式探讨

时间:2024-04-13 22:16:10
<!-- 方式二:外部依赖lib目录运行包 --> <!-- 将项目依赖包复制到<outputDirectory>指定的目录下 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.1.2</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <excludeArtifactIds>lombok</excludeArtifactIds> <includeScope>runtime</includeScope> <!-- 默认为test,包含所有依赖 --> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib</classpathPrefix> <mainClass>com.fly.simple.MainRun</mainClass> </manifest> <manifestEntries> <Class-Path>./</Class-Path> </manifestEntries> </archive> </configuration> </plugin>