maven创建项目,打包出可执行Jar
官网参考 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的更多相关文章
- 通过idea 打包 spring maven项目打包为可执行jar包
用assembly打包一直报错: shangyanshuodeMacBook-Pro:target shangyanshuo$ java -jar jobscrawler-1.0-SNAPSHOT-j ...
- (转载)Eclipse将引用了第三方jar包的Java项目打包成可执行jar的两种方法
转载自:http://www.cnblogs.com/lanxuezaipiao/p/3291641.html 方案一:用Eclipse自带的Export功能 步骤1:准备主清单文件 "MA ...
- 将Maven项目打包成可执行jar文件(引用第三方jar)
方法一. mvn assembly 或 mvn package (一个jar包) 把依赖包和自己项目的文件打包如同一个jar包(这种方式对spring的项目不支持) <build> ...
- Maven项目打包成可执行Jar文件
在使用Maven完成项目以后,如果需要打包成可执行的Jar文件,我们通过eclipse的导出很麻烦,还得指定入口文件的位置,还得说明依赖的jar包,既然都使用Maven了,很重要的一个目的就是让这些繁 ...
- 将Maven项目打包成可执行 jar文件(引用第三方jar)
使用maven assembly插件完成打包 修改pom: <build> <pluginManagement> <plugins> <!--设置jdk版本, ...
- java普通项目打包成可执行jar文件时如何添加第三包
在java的web项目中,引用第三方包的时候非常简单.因为在web项目上中,默认有一个web-inf文件夹.web-inf文件夹下有一个lib文件夹,如果有用到第三方包,直接丢进去就行了.但是对于普通 ...
- 如何将maven项目打包成可执行的jar
如何将maven项目打包成可执行的jar 分类: maven2010-12-17 10:18 10411人阅读 评论(2) 收藏 举报 jarmavenassemblyjava 方法一:将项目及所依赖 ...
- 【Maven】项目打包-war包-Jar包[IDEA将项目打成war包]
[Maven]项目打包-war包-Jar包[IDEA将项目打成war包] 2017年01月31日 00:21:06 阅读数:22912 标签: ideamaven发布博客插件 更多 个人分类: ❷ J ...
- Maven将java项目打包生成可运行jar
Maven将java项目打包生成可运行jar Maven插件配置 <plugins> <plugin> <groupId>org.apache.maven.plug ...
随机推荐
- Ring0创建事件Ring3设置事件
同步事件(synchronizationEvent)当事件对象为激发时,如遇到KeWaitForXX等内核函数,事件对象则自动变回未激发态通知事件(NotificationEvent)当事件对象为激发 ...
- GCViewer / MAT
jvm出现问题时,我们可以开启jmx功能,使用jvisualvm或者jconsole等监控其他机器上的jvm的运行情况,如https://www.cnblogs.com/princessd8251/p ...
- String MVC @RequestParam(required=false) int XXX 参数为空报错解决方法
今天在用@RequestParam(required=false) int XXX 取参数的时候,当参数没有的时候Spring默认赋值为空.而此时使用基本类型int,所以报错,建议使用包装类 Inte ...
- [UE4]反射
1.根据名字获得类(C++支持,蓝图本身不支持但可以通过工厂模式模拟) 国外大神提供的封装好的C++实现: https://github.com/getsetgames/BlueprintReflec ...
- MySQL分布式实现ID自增
由于数据量以及IO效率的因素,很多项目对数据支持的数据库会采取分库分表的方式.使用了分库分表之后需要解决的一个问题就是主键的生成.多个表之间的主键就不能用数据库本身的自增主键来支持,因为不同表之间生成 ...
- IDEA配置打可运行jar包
IDEA打包可以运行的jar包大体有两种方式:一种是比较方便的配置maven:一种是直接配置IDEA采用Build Artifacts打包. 配置maven打包,在pom.xml里面配置build插件 ...
- list函数
列表的切片: 获取: 1. [start:] 2. [:end] 3. [statr:end] 4. [statr: end: spet] 修改: listvar[:2] = ' 把0~1索引元素删除 ...
- POJ3635 Full Tank?
[题解] 用dijkstra算法求最短路.同时考虑在每个节点加油(一单位)与否. [代码] #include <iostream> #include <map> #includ ...
- Linux之间用SSH传输文件 一行命令实现
把本机的文件传到目标: cd /home/ && tar czv test | ssh root@HostIP -p 22 'tar xz' 解释: 如你所见,这行命令其实由多个命令组 ...
- 过滤器Filter的四种拦截方式
过滤器有四种拦截方式!分别是:REQUEST.FORWARD.INCLUDE.ERROR. REQUEST: 直接访问目标资源时执行过滤器.包括:在地址栏中直接访问.表单提交.超链接.重定向,只要在地 ...