maven 学习 十 关于打包
clean package -Dmaven.test.skip=true -P product
这个命令干的活: 清class文件,打包构建,跳过测试,注意最后一个 -P product, 会激活项目下的pom.xml配置的<profiles>标签下id为product。
Maven提供了Profile的概念来决绝不同环境打包的问题:
<profiles>
<profile>
<id>kaifa</id>
<properties>
<db.url>192.10.2.168</db.url>
<db.username>dbtest</db.username>
<db.password>dbtest</db.password>
</properties>
</profile> <profile>
<id>shengchan</id>
<properties>
<db.url>192.20.1.11</db.url>
<db.username>admin</db.username>
<db.password>comfreesecurity</db.password>
</properties>
</profile>
</profiles>
常用插件:
maven-jar-plugin
打成jar时,设定manifest的参数,比如指定运行的Main class,还有依赖的jar包,加入classpath中。
(classpath:classpath是Java运行时环境搜索类和其他资源文件(比如jar\zip等资源)的路径。可以通过JDK工具(比如javac命令、java命令)后面的-
classpath 参数设置classpath)
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>play.core.server.ProdServerStart</mainClass> // 主函数
<addClasspath>true</addClasspath> // 加入到classpath
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<!-- Add config folder into classpath of MANIFEST -->
<manifestEntries>
<Class-Path>conf/</Class-Path> // 资源文件也加入到classpath
</manifestEntries>
</archive>
<classesDirectory></classesDirectory>
<!--<excludes> <exclude>*.conf</exclude> <exclude>*.xml</exclude>
</excludes> -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>/data/lib</classpathPrefix>
<mainClass>com.zhang.spring.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
- maven-dependency-plugin
用于复制依赖的jar包到指定的文件夹里,
<plugin>
<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>
- maven-assembly-plugin
自定义打包方式。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor> // 具体的打包方式定义到assembly.xml文件中
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<assembly>
<id>dist</id>
<formats>
<format>zip</format> // 指定打包的格式
</formats>
<!-- set to false the archive created will unzip its content to the current directory. -->
<includeBaseDirectory>false</includeBaseDirectory> <fileSets>
<!-- copy file from target folder -->
<fileSet>
<directory>${basedir}/target</directory> // 把 这个路径下的所有*.jar文件打包到指定目录
<includes>
<include>*.jar</include>
</includes>
<outputDirectory></outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/target/lib</directory>
<outputDirectory>lib</outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/target/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>600</fileMode>
<lineEnding>unix</lineEnding>
</fileSet> <!-- copy file from source folder -->
<fileSet>
<directory>${basedir}/dist</directory>
<outputDirectory></outputDirectory>
<fileMode>744</fileMode>
<lineEnding>unix</lineEnding>
<includes>
<include>start</include>
<include>stop</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/src/main/resources</directory>
<excludes>
<exclude>logback-test.xml</exclude>
</excludes>
<outputDirectory>conf</outputDirectory>
<fileMode>600</fileMode>
<lineEnding>unix</lineEnding>
</fileSet>
</fileSets> <!-- <files>
<file>
<source>${basedir}/dist/README</source>
</file>
</files>-->
</assembly>
maven 学习 十 关于打包的更多相关文章
- Maven学习(十五)-----Maven常用命令
一.Maven常用命令 1.1.Maven 参数 -D 传入属性参数 -P 使用pom中指定的配置 -e 显示maven运行出错的信息 -o 离线执行命令,即不去远程仓库更新包 -X 显示ma ...
- Maven学习(十)-----使用Maven创建Java项目
所需要的工具: Maven 3.3.3 Eclipse 4.2 JDK 8 注意:请确保 Maven 是正确安装和配置(在Windows,*nix,Mac OSX系统中),然后再开始本教程,避免 mv ...
- Maven学习(十八)-----Maven依赖管理
其中一个Maven的核心特征是依赖管理.管理依赖关系变得困难的任务一旦我们处理多模块项目(包含数百个模块/子项目). Maven提供了一个高程度的控制来管理这样的场景. 传递依赖发现 这是很通常情况下 ...
- Maven学习(十六)-----Maven插件
Maven插件 Maven 是一个执行插件的框架,每一个任务实际上是由插件完成的.Maven 插件通常用于: 创建 jar 文件 创建 war 文件 编译代码文件 进行代码单元测试 创建项目文档 创建 ...
- Maven学习(十六)-----Maven存储库
什么是Maven资源库? 在 Maven 术语里存储库是一个目录,即目录中保存所有项目的 jar 库,插件或任何其他项目特定文件,并可以容易由 Maven 使用. Maven库中有三种类型 local ...
- Maven学习(十四)-----Maven 构建配置文件
Maven 构建配置文件 什么是构建配置文件? 生成配置文件是一组可以用来设置或覆盖 Maven 构建配置值的默认值.使用生成配置文件,你可以针对不同的环境,如:生产V/S开发环境自定义构建. 配置文 ...
- Maven学习(十二)-----Maven POM
Maven POM POM代表项目对象模型.它是 Maven 中工作的基本单位,这是一个 XML 文件.它始终保存在该项目基本目录中的 pom.xml 文件.POM 包含的项目是使用 Maven 来构 ...
- Maven学习-目录结构
在前一篇文章中,我们介绍了什么是Maven,以及如何用Maven来构建我们的项目.不了解Maven的童鞋,可以看这里Maven学习-入门.在这篇文章中,我们将学习Maven的项目的目录结构相关的内容. ...
- Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试
现在最新的Eclipse Luna Release 已经内置了Maven插件,这让我们的工作简洁了不少,只要把项目直接导入就可以,不用考虑插件什么的问题,但是导入之后的项目既可以部署在Tomcat也可 ...
随机推荐
- mini6410基于linux2.6.36内核通过NFS启动根文件系统总结(一搭建开发环境——建立NFS服务器)
http://blog.csdn.net/yinjiabin/article/details/7489030 建立 nfs 服务器 在嵌入式 linux 开发的时候,常常需要使用 nfs 以方便程序的 ...
- jsp连接sqlServer数据库教程、jsp连接sqlServer数据库报ClassNotFoundException异常
jsp连接sqlServer数据库教程: 首先讲下我用的工具版本以供参考: jar包:jtds1.3.1.jar 下载地址:点击进入 数据库:SQL Server2012 服务器:Tomcat8.0 ...
- iOS学习笔记之正则表达式
前言 基本上每个 App 都有登录注册功能,在登录注册时需要验证用户所输入的内容是否符合规定:有时要在字符串中查找并截取符合要求的字符串,这时就需要用到正则表达式.正则表达式看起来晦涩难懂,没有什么规 ...
- python中的字符串的种种函数
1.连接list:为了将任意包含字符串的 list 连接成单个字符串,可以使用字符串对象的 join 方法. join 只能用于元素是字符串的 list:它不进行任何的强制类型转换.连接一个存在一个或 ...
- mindmanager思维导图软件
Mindjet 由原名 Mindjet MindManager 简化而来,是倍受赞誉.最好的思维导图软件.所谓思维导图实际上就是一种将你的思想具体化,把你的思维分析整理为有计划有条理的导向图的工作管理 ...
- ural 2015 Zhenya moves from the dormitory(模拟)
2015. Zhenya moves from the dormitory Time limit: 1.0 secondMemory limit: 64 MB After moving from hi ...
- JAVA常见函数
输入函数 : Scanner cin=new Scanner(System.in); int a=cin.nextInt(); //输入一个int数据 double dl=cin.nextDou ...
- [项目部署] CentOs7 安装 MySQL/Tomcat/JDK 笔记
0.安装 MySQL cd /usr/local/ # 新增yum源 rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-.no ...
- skynet源码阅读<5>--协程调度模型
注:为方便理解,本文贴出的代码部分经过了缩减或展开,与实际skynet代码可能会有所出入. 作为一个skynet actor,在启动脚本被加载的过程中,总是要调用skynet.start和sky ...
- c++引用和指针的实现
引用和指针有什么区别?引用在进程中是否会分配内存? C++ primer中说: 引用就是对象的另一个名字. C++ primer中说: 指针用于指向对象,保存的是另一个对象的地址. 从字面意义上,感觉 ...