如何让一个简单的maven项目支持one-jar 做成一个jar fatjar

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>yourGoupid</groupId>
    <artifactId>yourArtifactId</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <!-- Includes the runtime dependencies -->
            <plugin>
                <groupId>com.jolira</groupId>
                <artifactId>onejar-maven-plugin</artifactId>
                <version>1.4.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>one-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>yourMainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
</project>

为了让一个简单的java程序,可以用java -jar yourJar.jar arg1 arg2 的形式方便的执行,通过one-jar-maven-plugin 插件可以打包成一个jar,另外为了指定Main-Class,还需要使用maven-jar-plugin指定 Main-Class。

参考 http://one-jar.sourceforge.net/

One-JAR lets you package a Java application together with its dependency Jars into a single executable Jar file.

posted @ 2017-01-18 15:13  极客堂  阅读(3371)  评论(0编辑  收藏  举报