网上有很多用Maven生成可运行jar的例子,但是大多都是将依赖的jar单独放在一个目录下,或者将依赖unpack后一起打在jar包中。找了很久终于在stackoverflow上找到一位牛人提供的解决方案:
[quote]
create an executable jar with dependencies using Maven:
using plugin - onejar-maven-plugin. Example below (mvn package build jar):
You need to add repository for that plugin:
[/quote]
[quote]
create an executable jar with dependencies using Maven:
using plugin - onejar-maven-plugin. Example below (mvn package build jar):
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<configuration>
<mainClass>com.company.MainClass</mainClass>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
You need to add repository for that plugin:
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
[/quote]