maven如何打包可运行的Jar

现在写后端非WEB程序比较多,每次需要手工的拷贝lib里面的jar 包,然后启动脚本里面还要写classpath,特么完全是在坑爹,为了偷懒,我找了一下maven中的配置,发现可以配置可运行包,并且直接拷贝依赖JAR到lib下,还把classpath放在打包好的程序描述文件中,简直是神器,这里留下一笔

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.coffee.bee.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
坚持原创技术分享,您的支持将鼓励我继续创作!