码迷,mamicode.com
首页 > 编程语言 > 详细

11) 生成可执行jar文件 maven-shade-plugin

时间:2016-08-02 23:54:23      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

搜索 site:maven.apache.org maven-assembly-plugin

http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

All goals except assembly:single have been deprecated.

以上不能使用,以下可以。

http://maven.apache.org/plugins/maven-shade-plugin/

examples

Executable JAR

1. pom.xml

<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>cn.zno</groupId>
    <artifactId>executable</artifactId>
    <version>1.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>cn.zno.commandline.Test</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

 2. Test.java

package cn.zno.commandline;

import java.lang.management.ManagementFactory;

public class Test {
    public static void main(String[] args) {
        System.out.println("VM arguments:" + ManagementFactory.getRuntimeMXBean().getInputArguments());
        System.out.println("Program arguments:");
        for (String arg : args) {
            System.out.println(arg);
        }
    }
}

打包

mvn install 

we will see an entry like this in the META-INF/MANIFEST.MF file of the resulting JAR:

Manifest-Version: 1.0
Build-Jdk: 1.7.0_15
Built-By: Administrator
Created-By: Apache Maven
Main-Class: cn.zno.commandline.Test
Archiver-Version: Plexus Archiver

测试可执行jar文件

java [-options] -jar jarfile [args...]

E:\e\workspace\executable\target>java -Xms32m -Xmx32m -jar executable-1.0.jar a b
VM arguments:[-Xms32m, -Xmx32m]
Program arguments:
a
b

 

11) 生成可执行jar文件 maven-shade-plugin

标签:

原文地址:http://www.cnblogs.com/zno2/p/4571189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!