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. linux安装Zabbix监控

    源码包3.4.0下载  https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.0/zabbix-3.4 ...

  2. EntityFramework 学习 一 Multiple Diagrams in Entity Framework 5.0

    Visual Studio 2012 provides a facility to split the design time visual representation of the Entity ...

  3. 在物理机安装CentOS6.5

    这两天就要开始在用户的新服务器上部署生产环境了.之前一直都是在服务器上搭虚拟机,而在物理机上安装还是第一次. 首先是要准备启动程序.我用的U盘作为启动盘. 刻盘的操作参考 http://jingyan ...

  4. Avoid nesting too deeply and return early避免嵌套太深应尽早返回

    当某个变量与多个值进行比较的时候 不要用多个if else 判断是否相等 将多个值放在数组里,然后用PHP函数in_array(mixed $needle,array $haystack),检查数组$ ...

  5. STL视频_02

    [01:05]主要讲一下几个要点: 1.模板.函数模板 类模板 以及它们的用法 2.容器.什么是容器 和 容器的分类,各种容器的数据结构 3.容器vector的具体用法,包括迭代器的具体用法 [01: ...

  6. nginx基本参数详解

    运行用户 user nobody; 启动进程,通常设置成和cpu的数量相等 worker_processes 1; 全局错误日志及PID文件 error_log logs/error.log; err ...

  7. Shiro安全配置

    主要还是整合了本地ehcache,集群session管理过段时间放出 <?xml version="1.0" encoding="UTF-8"?> ...

  8. MongoDB 高可用集群搭建(3.4)

      一.架构概况192.168.56.101192.168.56.102192.168.56.103OS为centos 7.2 架构图: 规划5个组件对应的端口号,由于每台机器均需要同时部署 mong ...

  9. c++primer 第二章编程练习答案

    2.7.1 #include<iostream> int main() { using namespace std; ]; ]; cout << "input nam ...

  10. Project://Meeting_Room

    models from django.db import models from django.contrib.auth.models import AbstractUser class UserIn ...