Maven打jar发布包的常用配置
1.修改pom.xml增加如下内容
![](/assets/blank.gif)
![](/assets/blank.gif)
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.sysware.HelloWorld</mainClass> </manifest> </archive> </configuration> </plugin>
View Code
运行mvn clean package即可
2.在pom.xml增加如下内容
![](/assets/blank.gif)
![](/assets/blank.gif)
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.3</version> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution> </executions> </plugin>
View Code
运行mvn assembly:assembly
3.
![](/assets/blank.gif)
![](/assets/blank.gif)
<build> <finalName>...</finalName> <sourceDirectory>src/main/java</sourceDirectory> <resources> <!-- 控制资源文件的拷贝 --> <resource> <directory>src/main/resources</directory> <targetPath>${project.build.directory}</targetPath> </resource> </resources> <plugins> <!-- 设置源文件编码方式 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <defaultLibBundleDir>lib</defaultLibBundleDir> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>.....MonitorMain</mainClass> </manifest> </archive> </configuration> </plugin> <!-- 拷贝依赖的jar包到lib目录 --> <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}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> <!-- 解决资源文件的编码问题 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打包source文件为jar文件 --> <plugin> <artifactId>maven-source-plugin</artifactId> <version>2.1</version> <configuration> <attach>true</attach> <encoding>UTF-8</encoding> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
View Code
4.
![](/assets/blank.gif)
![](/assets/blank.gif)
<build> <resources> <resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.0</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.test.testguava.app.App</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>applicationContext.xml</resource> </transformer> </transformers> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>executable</shadedClassifierName> </configuration> </execution> </executions> </plugin> </plugins> </build>
View Code
Maven打jar发布包的常用配置相关推荐
- 发布包到maven公共仓库图文教程(2) --- gpg签名和pom.xml的配置等
在操作这篇文章之前你需要做一些账号注册和提交申请前置操作, 前置操作我已经写了另一篇博客, 请移步 链接在此. 这篇接着讲如何使用gpg和和配置发布信息. 因为内容有点多, 所以最重要的打包和发布环节 ...
- Maven pom.xml 全配置(一)常用配置
Maven pom.xml 全配置(一)常用配置 这里贴出一个Maven中出现频率较高的配置参数注释,方便理解项目中Maven的配置具体的作用.如果在此博文中没有找到你想看到的参数,可以移步Maven ...
- 发布包到maven公共仓库图文教程(1) --- 注册账号和提交申请
当你有个很好的想法, 写了一个开源的项目,想发布到maven公共仓库给别人用的时候, 你可能就需要这篇教程. 整个教程分三篇博客讲解 第一篇: 注册账号和提交申请 第二篇: 安装gpg和配置pom.x ...
- Maven pom.xml 全配置(二)不常用配置
Maven pom.xml 全配置(二)不常用配置 这里贴出Maven pom.xml文件中使用率较少的配置参数,如果此篇文档中没有找到你想要的参数,移步Maven pom.xml 全配置(一)常用配 ...
- Maven:解决jar包冲突和企业开发常用编写
QUESTION:Maven:解决jar包冲突和企业开发常用编写 目录 QUESTION:Maven:解决jar包冲突和企业开发常用编写 ANSWER: 一:Maven的作用 二:解决jar包冲突: ...
- Maven 项目查找 jar 包是由哪个配置引入的
maven依赖结构图 1.项目查询所有的Maven查看JAR包的依赖关系 mvn dependency:tree 如查询junit.jar 是依赖谁导入进来的 这样就知道是被谁依赖而导入到项目的 其中 ...
- 关于日志的常用配置(log4j和logback)
**log4j配置** 注:在配置log4j前要在web.xml中进行配置,告诉框架采用自定义的配置 pom配置 <!-- 设置根目录 --> <context-param> ...
- Maven下载jar包失败的原因- 解决方法汇总
前言 我个人对Maven没有多少研究,仅仅是使用层面,但是有时候在IDEA中配置好Maven,写好pom.xml文件后,经常下载一会就停止了,也就是有些jar包并没有下载成功.我从网上搜了一下,发现大 ...
- idea 常用配置介绍(一)
最近开始使用idea,做为一个Java程序员,一直都在使用eclipse,感觉eclipse用习惯了,其他的工具写Java都感觉不适应,无论是图形化界面还是提示都用一个词来表示,那就是完美 但经常逛各 ...
- SpringBoot2.x系列教程11--小花样之SpringBoot其他常用配置
SpringBoot系列教程11--小花样之SpringBoot其他常用配置 作者:一一哥 一. 修改端口号和访问路径 在Spring Boot 项目中会使用一个全局的配置文件application. ...
最新文章
- 面向连接的Socket Server的简单实现
- 【Paper】2021_Analysis of the Consensus Protocol of Heterogeneous Agents with Time-Delays
- 【风控模型】Logistic算法构建标准信用评分卡模型python代码案例
- python线程任务run_python线程、进程知识梳理
- 企业微信_通讯录管理,获取部门列表部门成员及详情
- linux 音频转换工具,Linux 音频格式转换初探
- Xweibo2.0nbsp;游客可以访问任何页面【…
- 手心输入法导致 Navicat for MySQL闪退的解决办法
- 详细教您如何把wav转换成mp3格式
- Java生成文本水印
- 关于光的波粒二象性的解释--答复年少时的疑惑
- 又一大的技术站点域名被ClientHold了
- PHP中获取字符串长度的使用方法
- 浅聊前端程序员,后端程序员,全栈程序员的工作
- C语言中的字符常量与变量
- Google analytics是什么,有什么作用
- python装饰器带参数函数二阶导数公式_SICP Python 描述 1.6 高阶函数
- 数据仓库—stg层_数据仓库(一):认识数据仓库
- Rufus制作USB启动盘工具 重装系统
- Mac OS下安装串口调试工具minicom