maven javaproject工程打可执行jar包
Posted 要千
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven javaproject工程打可执行jar包相关的知识,希望对你有一定的参考价值。
pom.xml配置 主要配置在插件这块
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<!-- 测试类打成单独的jar包 -->
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<!-- 打成可执行的jar包 -->
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<!-- 主方法所在类名 -->
<mainClass>com.sense.test.KeyTest</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin><!-- 将依赖的jar包打到lib包中 -->
<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>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- <excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes> -->
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
使用maven install 打包,将在target下生成项目jar包xxx.jar及lib文件夹,将这两者放在同一目录下,执行java -jar xxx.jar即可运行
以上是关于maven javaproject工程打可执行jar包的主要内容,如果未能解决你的问题,请参考以下文章