Maven 打包可运行 jar
为配合自动化部署hudson,最近研究了如何将eclipse maven工程打包成可运行的jar函数及对应的资源文件。
由于我们工程中包含了多个可运行的任务,在打包成jar时需要分别导出,pom提到版本库需要一致,不能部署一个任务提交一次代码。所以考虑了在进行mvn打包时通过传递参数控制导出jar中的main所在的类。在pom中定义properties,在执行命令时传递参数即可。如mvn package -DtaskFinalName=contentpoolurl -DmainClassName=com.ifec.blueair.task.contentpoolurl.ContentPoolUrlRun,另外在通过mvn导出jar找不到配置文件,发现没有找到当前目录,通过加入manifestEntries即可指定目录。maven生成的MANIFEST.MF中的Class-Path的内容缺少一些内容,比如当前执行目录(.),那么可以通过上面manifestEntries的方式增加进来。
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>
<parent>
<groupId>com.ifec.blueair</groupId>
<artifactId>blueair-packagemanager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../blueair-packagemanager/pom.xml</relativePath>
</parent>
<artifactId>blueair-task</artifactId>
<packaging>jar</packaging>
<name>blueair-task</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<propertiesName>contentpoolurl</propertiesName>
<taskFinalName>contentpoolurl</taskFinalName>
<mainClassName>com.ifec.blueair.task.contentpoolurl.ContentPoolUrlRun</mainClassName>
</properties>
<build>
<finalName>${taskFinalName}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sh</include>
<include>**/${propertiesName}.properties</include>
<include>**/log4j.properties</include>
<include>**/config.properties</include>
</includes>
<filtering>true</filtering>
<targetPath>${project.build.directory}</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${taskFinalName}_lib</classpathPrefix>
<mainClass>${mainClassName}</mainClass>
</manifest> <!--maven生成的MANIFEST.MF中的Class-Path的内容缺少一些内容,比如当前执行目录(.),那么可以通过上面manifestEntries的方式增加进来。-->
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/${taskFinalName}_lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
</dependencies>
</project>
Maven 打包可运行 jar的更多相关文章
- spring boot maven打包可运行jar包
普通打包之后在程序目录运行,或者编写bat运行时会提示“没有主清单属性”,这是因为并没有找到main()方法,需要我们指明告诉java程序 我bat中的代码 @echo off title mytit ...
- 使用Maven打包可运行jar和javaagent.jar的区别
简介 javaagent 是 Java1.5 之后引入的新特性,其主要作用是在class被加载之前对其拦截,以插入我们的字节码. java1.5 之前使用的是JVMTI(jvm tool interf ...
- maven 打包可运行jar包(转)
目录 1.前提 2.方法一:使用maven-jar-plugin和maven-dependency-plugin插件打包 3.方法二:使用maven-assembly-plugin插件打包 4.方法三 ...
- 利用MAVEN打包可运行jar包,包括依赖的第三方包
转载自:http://bglmmz.iteye.com/blog/2058914 背景: 另一篇文章说了如何利用IDEA来打包,现在来说说如何利用MAVEN打包 目标:应用本身打成一个jar包,依赖的 ...
- maven打包 tomcat运行pom配置 或 打成jar包
maven打包 tomcat运行pom配置,同时还需要配置org.apache.tomcat.maven插件,这里省略. <groupId>com.company</groupId& ...
- 【Maven学习】Maven打包生成普通jar包、可运行jar包、包含所有依赖的jar包
http://blog.csdn.net/u013177446/article/details/54134394 ******************************************* ...
- 关于 maven 打包直接运行的 fat jar (uber jar) 时需要包含本地文件系统第三方 jar 文件的问题
关于maven打包fat jar (uber jar) 时需要包含本地文件系统第三方jar文件的问题,今天折腾了一整天.最后还是用了spring boot来做.下面是几篇关于打包的有参考价值的文章,以 ...
- idea在maven打包时运行Test测试, 导致打包失败, 乱七八糟的错误
在maven打包时运行Test测试, 导致打包失败, 乱七八糟的错误 在maven projects中图标toggle'skip Tests' Mode //宏杰帮助 网上案例:https://blo ...
- springboot(六) Maven打包引入本地jar包
springboot Maven打包引入本地jar包 最近在做项目的时候,有一些jar包不存在maven的依赖库中,所以需要自己引入本地jar包来达到需求,那么我们该如何去将本地的jar包引入s ...
随机推荐
- python使用PIL压缩图片
import Image import os import os.path import sys path = sys.argv[1] small_path = (path[:-1] if path[ ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)README 算法的部分英文解释
This is the Readme file for NSGA-II code. About the Algorithm--------------------------------------- ...
- Mifare 1卡的存储结构
存取控制指符合什么条件才能对卡片进行操作. S50和S70的块分为数据块和控制块,对数据块的操作有“读”.“写”.“加值”.“减值(含传输和存储)”四种,对控制块的操作只有“读”和“写”两种. S50 ...
- (未解决)android studio:com.android.support:appcompat-v7:22+ Could not found
错误信息如下: Error:Could not +. Searched in the following locations: https://jcenter.bintray.com/com/andr ...
- poj Fishnet
http://poj.org/problem?id=1408 #include<cstdio> #include<cstring> #include<cmath> ...
- 向Int数组插入随机1到100
这是一个经典的面试题,考察了几个知识点 下边的代码是传统经典的做法 ]; ArrayList myList=new ArrayList(); Random rnd=new Random(); ) { ...
- 【动态规划】XMU 1028 Game Boy Advance
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1028 题目大意: 求01背包最优解的方案.物件数和物件编号. 题目思路: [动态规划] ...
- 怎么都没人提 google 加密搜索呢? google如何稳定打开
1. 使用smarthosts提供的hosts文件 https://smarthosts.googlecode.com/svn/trunk/hosts2. 修改浏览器默认搜索引擎为 https://e ...
- webex录屏
你在寻找好用的录屏软件吗?商用级品质的 WebEx Recorder 就是一款优秀的录屏软件.WebEx Recorder可以录制全屏或指定窗口,可以设定是否包含声音,生成的文件体积极小且极清晰,录制 ...
- Going Home - poj 2195(最小费用流 | 二分匹配)
题目大意:在一个网格里面有n个小男人和n个房子,现在想让每个小男人都有一个房子住,不过每个人移动一下都需要花费¥1,现在求出来最小的总花费.ps:可以认为网格的每个点都是很大的广场并且容纳所有的人,人 ...