官网参考 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html 配置多种打包方式

这个例子也不错 https://blog.csdn.net/u010010606/article/details/79758030

想弄一个maven打出来可执行的jar

mvn archetype:generate   创建一个mvn项目,输入一系列创建参数后,成功。

mvn dependency:copy-dependencies -DoutputDirectory=target/lib 可以将依赖的包导出到某个目录

然后做如下修改,加入依赖,并且为了将内容打包到执行的Jar,需要加入assembly,并制定打包后执行的主类

<?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>com.test</groupId>
<artifactId>netty</artifactId>
<version>1.0</version> <name>netty</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> <dependencies>
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.31.Final</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.test.netty.Server</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</pluginManagement>
</build>
</project>

执行命令打包

mvn assembly:assembly

运行jar

java -jar ***.jar

定制打包描述文件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>assemble</id>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>***/assembly1.xml</descriptor>
</descriptors>
</configuration>
</execution>
<execution>
<id>targz</id>
<goals>
<goal>single</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptors>
<descriptor>***/assembly2.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>

assembly1.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>tgz</id>
<!-- 应用名-run(压缩包解压后的目录名) -->
<baseDirectory>/</baseDirectory>
<formats>
<format>dir</format>
</formats> <fileSets>
<fileSet>
<directory>src/bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<directory>src/conf</directory>
<outputDirectory>conf</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<!-- 运行时依赖统一放在lib目录下 -->
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>

assembly2.xml

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>tgz</id>
<!-- 应用名-run(压缩包解压后的目录名) -->
<baseDirectory>quarkservice-run-${project.version}</baseDirectory>
<formats>
<format>tar.gz</format>
</formats> <fileSets>
<fileSet>
<directory>${project.build.directory}/${project.build.finalName}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>

maven创建项目,打包出可执行Jar的更多相关文章

  1. 通过idea 打包 spring maven项目打包为可执行jar包

    用assembly打包一直报错: shangyanshuodeMacBook-Pro:target shangyanshuo$ java -jar jobscrawler-1.0-SNAPSHOT-j ...

  2. (转载)Eclipse将引用了第三方jar包的Java项目打包成可执行jar的两种方法

    转载自:http://www.cnblogs.com/lanxuezaipiao/p/3291641.html 方案一:用Eclipse自带的Export功能 步骤1:准备主清单文件 "MA ...

  3. 将Maven项目打包成可执行jar文件(引用第三方jar)

    方法一. mvn assembly 或 mvn package (一个jar包) 把依赖包和自己项目的文件打包如同一个jar包(这种方式对spring的项目不支持) <build>     ...

  4. Maven项目打包成可执行Jar文件

    在使用Maven完成项目以后,如果需要打包成可执行的Jar文件,我们通过eclipse的导出很麻烦,还得指定入口文件的位置,还得说明依赖的jar包,既然都使用Maven了,很重要的一个目的就是让这些繁 ...

  5. 将Maven项目打包成可执行 jar文件(引用第三方jar)

    使用maven assembly插件完成打包 修改pom: <build> <pluginManagement> <plugins> <!--设置jdk版本, ...

  6. java普通项目打包成可执行jar文件时如何添加第三包

    在java的web项目中,引用第三方包的时候非常简单.因为在web项目上中,默认有一个web-inf文件夹.web-inf文件夹下有一个lib文件夹,如果有用到第三方包,直接丢进去就行了.但是对于普通 ...

  7. 如何将maven项目打包成可执行的jar

    如何将maven项目打包成可执行的jar 分类: maven2010-12-17 10:18 10411人阅读 评论(2) 收藏 举报 jarmavenassemblyjava 方法一:将项目及所依赖 ...

  8. 【Maven】项目打包-war包-Jar包[IDEA将项目打成war包]

    [Maven]项目打包-war包-Jar包[IDEA将项目打成war包] 2017年01月31日 00:21:06 阅读数:22912 标签: ideamaven发布博客插件 更多 个人分类: ❷ J ...

  9. Maven将java项目打包生成可运行jar

    Maven将java项目打包生成可运行jar Maven插件配置 <plugins> <plugin> <groupId>org.apache.maven.plug ...

随机推荐

  1. Hive学习笔记一

    1. Load的使用 //在1.x版本中定义long数据类型会报错(用bigint代替) create table t_load_stu(name string,age bigint) row for ...

  2. 市值3万亿的facebook再出丑闻,你的数据,到底应该归谁?

    最近一则<Facebook隐私泄露事件继续发酵,黑客明码标价出售聊天信息>的新闻被爆出,一个用户的信息被标价10美分.让人不禁感慨,3万亿市值的facebook,用户数据竟然如此便宜. 在 ...

  3. Jmeter(三十四)Jmeter-Question之“Cookie获取”

    2018.4.27 还在做性能测试的过程中,唉,只能说坑很多. 无明确需求.无人手协调等问题,什么都需要自己去挖掘. 本次测试的工具选型依然是Jmeter,真实场景中遇到了这么个问题.可能解决办法有点 ...

  4. Jmeter(十五)Logic Controllers 之 while Controller

    while Controller是控制循环的Controller,条件判断的Controller.先看看官方Demo. while Controller控制它的子对象,直到false为止.并且还提供了 ...

  5. [UE4]手持多把枪的位置调节

    如果一个角色有多把枪,但是骨骼插槽只有一个,可以通过直接在枪蓝图中调整枪的位置和旋转角度.

  6. [UE4]寻找敌人

  7. C#语言,求成绩平均数。

    输入大于五的人数成绩,去掉两个最高分,和两个最低分,求其平均数. Console.Write("请输入人数"); int renshu = int.Parse(Console.Re ...

  8. js之DOM

    DOM对象 什么是HTML  DOM HTML  Document Object Model(文档对象模型) HTML DOM 定义了访问和操作HTML文档的标准方法 HTML DOM 把 HTML ...

  9. Django中的视图

    Django的View(视图) 一个视图函数(类),简称视图,是一个简单的Python 函数(类),它接受Web请求并且返回Web响应. 响应可以是一张网页的HTML内容,一个重定向,一个404错误, ...

  10. python函数的return

    return语句用于退出函数,向调用方返回一个表达式.return在不带参数的情况下(或者没有写return语句),默认返回None.None是一个特殊的值,它的数据类型是NoneType.NoneT ...