mvn 打包jar文件

一、使用maven-assembly-plugin插件打包

<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.5.5</version>
          <configuration>
            <archive>
              <manifest>
                <!-- com.cn.demo.TestClient1 -->
                <mainClass>com.cn.demo.App</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
        </plugin>

命令:

mvn package assembly:single

二、commandline 

 应用程序入口App()

package com.cn.demo;

import org.apache.commons.cli.*;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )throws ParseException
    {
        Options options = new Options();
        /**
         * 1、初始化命令
         *  opt : n 在命令行输入: java -jar demo.jar -n 参数1
         *  longOpt :  namesrvAddr 是 n 的全写方式 ,与 opt 一致
         */

        Option opt = new Option("n", "namesrvAddr", true,"Name server address list, eg: 192.168.0.1:9876;192.168.0.2:9876");
        opt.setRequired(true);//true 在命令行的时候必须要添加参数, false 没有参数也可以
        options.addOption(opt);

        CommandLineParser parser = new DefaultParser();
        CommandLine commandLine = parser.parse(options, args);

        String optNmae = "n";
        if (commandLine.hasOption(optNmae)) {
            for (String s : commandLine.getOptionValues(optNmae)) {
                System.out.print(s+" ");
            }
            //调业务代码
            new UserService().test1();
        }
    }
}

三、新增 MANIFEST.MF

第一步
第一步

 

第二步
第二步

 

标题第三步

 

MAINFEST.MF

 

运行:

java -jar Demo-1.0-SNAPSHOT-jar-with-dependencies.jar -n 192.168.0.1:9876

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值