zoukankan      html  css  js  c++  java
  • Maven项目导出可执行jar

    配置文件中添加插件

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.1.1</version>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
    
                                <!-- 主程序入口类 -->
                                <mainClass>com.java.demo.JsonDemo</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

    示例如下:

    1.   新建Maven项目 exe-jar

    2.   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>com.java</groupId>
        <artifactId>exe-jar</artifactId>
        <version>1.0.0</version>
    
        <dependencies>
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.56</version>
            </dependency>
    
        </dependencies>
    
        <build>
            <finalName>${project.artifactId}</finalName>
    
            <plugins>
    
                <!-- 编译插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
    
                <!-- 打包插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.1.1</version>
                    <configuration>
                        <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
    
                                <!-- 主程序入口类 -->
                                <mainClass>com.java.demo.JsonDemo</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
            </plugins>
        </build>
    </project>

    3.   JsonDemo.java

    package com.java.demo;
    
    import com.alibaba.fastjson.JSON;
    
    public class JsonDemo {
    
        public static void main(String[] args) {
            System.out.println(JSON.toJSONString(args, true));
        }
    
    }

    4.   在项目上单击右键 》 Run As 》 Maven build... 》。 如下图:

     

    在Goals 里输入 clean package , 单击【Run】。如下图

     控制台打出BUILD SUCCESS ,打包完成。

    打开target 目录,测试运行

    在命令行窗口输入

    java -jar exe-jar.jar Hello Good Hi

    回车执行,如下图

     

    控制台打印结果:

    ["Hello","Good","Hi"]

    打包成功。

    .

  • 相关阅读:
    Mysql模糊查询like效率,以及更高效的写法(转)
    补全数组缺失某种类型的数据方法
    php 判断两个数组是否相等
    query如何全选或不全选时,不操作已经禁用的checkbox
    css talbe中td溢出隐藏 div溢出隐藏
    MongoDb的安装
    PSR规范
    shell中各种括号的作用()、(())、[]、[[]]、{}
    mysql explain执行计划详解
    PHP "延迟静态绑定" 功能,static
  • 原文地址:https://www.cnblogs.com/jonban/p/10695525.html
Copyright © 2011-2022 走看看