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


    搜索 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:eworkspaceexecutable	arget>java -Xms32m -Xmx32m -jar executable-1.0.jar a b
    VM arguments:[-Xms32m, -Xmx32m]
    Program arguments:
    a
    b
  • 相关阅读:
    ServiceStack.Redis之IRedisClient<第三篇>【转】
    Redis常用命令速查 <第二篇>【转】
    Redis 安装与简单示例 <第一篇>【转】
    OKHttp使用简介
    android studio快捷键
    android客户端向java服务端post发送json
    安卓开发--HttpDemo02
    安卓开发--HttpDemo01
    安卓开发--HttpClient
    安卓开发--AsyncTask2
  • 原文地址:https://www.cnblogs.com/zno2/p/4571189.html
Copyright © 2020-2023  润新知