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 学习 十 关于打包的更多相关文章

  1. Maven学习(十五)-----Maven常用命令

    一.Maven常用命令 1.1.Maven 参数 -D 传入属性参数  -P 使用pom中指定的配置  -e 显示maven运行出错的信息  -o 离线执行命令,即不去远程仓库更新包  -X 显示ma ...

  2. Maven学习(十)-----使用Maven创建Java项目

    所需要的工具: Maven 3.3.3 Eclipse 4.2 JDK 8 注意:请确保 Maven 是正确安装和配置(在Windows,*nix,Mac OSX系统中),然后再开始本教程,避免 mv ...

  3. Maven学习(十八)-----Maven依赖管理

    其中一个Maven的核心特征是依赖管理.管理依赖关系变得困难的任务一旦我们处理多模块项目(包含数百个模块/子项目). Maven提供了一个高程度的控制来管理这样的场景. 传递依赖发现 这是很通常情况下 ...

  4. Maven学习(十六)-----Maven插件

    Maven插件 Maven 是一个执行插件的框架,每一个任务实际上是由插件完成的.Maven 插件通常用于: 创建 jar 文件 创建 war 文件 编译代码文件 进行代码单元测试 创建项目文档 创建 ...

  5. Maven学习(十六)-----Maven存储库

    什么是Maven资源库? 在 Maven 术语里存储库是一个目录,即目录中保存所有项目的 jar 库,插件或任何其他项目特定文件,并可以容易由 Maven 使用. Maven库中有三种类型 local ...

  6. Maven学习(十四)-----Maven 构建配置文件

    Maven 构建配置文件 什么是构建配置文件? 生成配置文件是一组可以用来设置或覆盖 Maven 构建配置值的默认值.使用生成配置文件,你可以针对不同的环境,如:生产V/S开发环境自定义构建. 配置文 ...

  7. Maven学习(十二)-----Maven POM

    Maven POM POM代表项目对象模型.它是 Maven 中工作的基本单位,这是一个 XML 文件.它始终保存在该项目基本目录中的 pom.xml 文件.POM 包含的项目是使用 Maven 来构 ...

  8. Maven学习-目录结构

    在前一篇文章中,我们介绍了什么是Maven,以及如何用Maven来构建我们的项目.不了解Maven的童鞋,可以看这里Maven学习-入门.在这篇文章中,我们将学习Maven的项目的目录结构相关的内容. ...

  9. Maven学习笔记-03-Eclipse下maven项目在Tomcat7和Jetty6中部署调试

    现在最新的Eclipse Luna Release 已经内置了Maven插件,这让我们的工作简洁了不少,只要把项目直接导入就可以,不用考虑插件什么的问题,但是导入之后的项目既可以部署在Tomcat也可 ...

随机推荐

  1. oracle中检索结果汉字首字母排序详解

    今天写需求,要求将结果按照成本中心首字母排序,平且空放在最前面. 进入正题: 1.使用oracle自带的函数: 按照首字母排序:nlssort(xxx,'NLS_SORT=SCHINESE_PINYI ...

  2. 2.mysql高级查询

    01.SQL高级查询_排序     1.排序语句:order by 排序字段名  asc(默认的-升序) / desc(降序);     2.例如:查询所有服装类商品,将查询结果以价格升序排序:   ...

  3. QT中phonon的安装和使用

    http://write.blog.csdn.net/postedit Phonon严格来说其实非为Qt的library,Phonon原本就是KDE 4的开放原始码多媒体API,後来与Qt合并与开发, ...

  4. JVM内存管理中的垃圾回收策略

    JVM垃圾回收策略 1.静态内存分配和回收 编译时已经确定了内存空间大小,程序被加载后则一次性分配好内存空间.程序结束后,则对应栈帧撤销,分配的静态内存空间则被回收. 2.动态内存分配和回收 程序运行 ...

  5. Advanced SQL: Relational division in jOOQ

              i   Rate This Relational algebra has its treats. One of the most academic features is the ...

  6. Android环境配好的标志

    Window —> preference —> android

  7. ElasticSearch_学习_00_资源帖

    一.官方资料 1.Elasticsearch 权威指南(中文版) 二.精选资料 1. 全文搜索引擎 Elasticsearch 入门教程-阮一峰 2. 三.参考资料

  8. L121

    今天上午签字仪式的布置与该场合的严肃性非常协调.The setting for this morning's signing ceremony matched the solemnity of the ...

  9. BackBone 源码解读及思考

    说明 前段时间略忙,终于找到时间看看backbone代码. 正如知友们说的那样,backbone简单.随性. 代码简单的看一眼,就能知道作者的思路.因为简单,所以随性,可以很自由的和其他类库大搭配使用 ...

  10. stl_algobase.h

    stl_algobase.h // Filename: stl_algobase.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: ...