任何一个maven项目都会继承一个默认的父pom配置:Super POM,详见:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

在pom.xml中可以直接使用一些变量值,如:

${project.groupId}               The group id of current project
${project.version}          The version of current project
${project.build.sourceDirectory} The source directory of current project
${project.basedir} The directory that the current project resides in.
${project.baseUri} The directory that the current project resides in, represented as an URI. Since Maven 2.1.0
${maven.build.timestamp} The timestamp that denotes the start of the build. Since Maven 2.1.0-M1

详见:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html之Available Variables

一个实际完整的maven项目pom.xml文件配置框架:

<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion> <!-- 模块参数 -->
<artifactId>xxx-xxx</artifactId>
<version>x.x.x</version>
<packaging>war</packaging>
<name>xxx</name>
<url>xxx</url> <!-- 父模块,可选. -->
<parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>x.x.x</version>
</parent> <!-- 定义属性 -->
<properties>
<!-- 项目编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 时间格式 -->
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
</properties> <!-- 依赖配置 -->
<dependencies>
<dependency>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>x.x.x</version>
</dependency>
</dependencies> <!-- 定义profile: 将开发配置和生产配置分离开 -->
<profiles>
<profile>
<id>dev</id>
<properties>
<profile.dir>dev</profile.dir>
</properties>
<activation>
<activeByDefault>dev</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profile.dir>test</profile.dir>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profile.dir>prod</profile.dir>
</properties>
</profile>
</profiles> <!-- 打包 -->
<build>
<finalName>xxx</finalName> <!-- 打包资源 -->
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>.svn</exclude>
<exclude>.java</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/profiles/${profile.dir}</directory>
<excludes>
<exclude>.svn</exclude>
</excludes>
</resource>
</resources> <!-- 配置打包插件,如: 依赖处理,资源复制,压缩打包等 -->
<plugins>
<!-- 生成jar包时打包资源文件配置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>**/profiles/**</exclude>
<exclude>**/jdbc.properties</exclude>
<exclude>**/*.proto</exclude>
</excludes>
</configuration>
</plugin> <!-- 打包源码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin> <!-- 打包编译参数 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <!-- 将依赖模块的jar包文件提取出来放到指定位置 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.xxx</groupId>
<artifactId>xxx-xxx</artifactId>
<version>1.0.0</version>
<type>jar</type>
<includes>**/*.class</includes>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin> <!-- 打包可执行jar文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.chench.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin> <!-- 构建时不执行单元测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>

maven项目配置框架的更多相关文章

  1. maven项目配置findbugs插件 使用git钩子控制代码的提交

    maven项目配置findbugs插件对代码进行静态检测 当发现代码有bug时,就不让用户commit代码到远程仓库里 没有bug时才可以commit到远程仓库中 (1)新建maven项目 ,配置fi ...

  2. maven项目配置使用jdk1.8进行编译的插件

    在使用Maven插件编译Maven项目的时候报了这样一个错:[Java source1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符],这里记录下出现这个错 ...

  3. maven项目ssh框架的整合

    1.环境 eclipse版本:Eclipse Mars2 4.5jdk版本:1.8maven版本:apache-maven 3.3.9zhnegs这是主要的开发工具版本,ssh的各种jar包版本就不列 ...

  4. maven项目快速搭建SSM框架(一)创建maven项目,SSM框架整合,Spring+Springmvc+Mybatis

    首先了解服务器开发的三层架构,分配相应的任务,这样就能明确目标,根据相应的需求去编写相应的操作. 服务器开发,大致分为三层,分别是: 表现层 业务层 持久层 我们用到的框架分别是Spring+Spri ...

  5. maven 项目配置

    创建java web的maven项目方法有两种,一是先创建maven项目,再选择jdk 和 dynamic web 运行环境 ,二是创建java项目,然后转化为maven项目 1.将普通java项目转 ...

  6. apache log4j日志工具使用入门[maven 项目配置]

    简单的介绍下Maven项目中有关org.apache.log4j.Logger的使用.[1]首先我们需要找到 org.apache.log4j.Logger的坐标,并配置到POM.xml <de ...

  7. 【IDEA】本地新建Maven项目+配置Git和GitHub+代码上传和拉取到GitHub+其他IDEA和GitHub实战

    一.本地新建Maven项目并启动成功 1. 按照IDEA提供的模板,构建一个maven webapp的模板项目. 一路Next,到最后的finish.如下图. 2. 新建Tomcat,启动刚建立的项目 ...

  8. Maven项目配置Logback输出JSON格式日志

    最近,项目提出需求,日志需要固定输出为JSON格式,以便后端Flink程序解析. 项目背景 项目为简单的Maven项目,日志由Filebeat采集,因此不需要配置输出至Logstash. 下面为pom ...

  9. maven 项目配置到tomcat不能正常启动

    最近使用IntelliJ IDEA搭建公司项目,该项目是maven项目,加载jar和编译的时候没有任何异常,但是部署到tomcat上之后,就会出现如下异常: org.apache.catalina.L ...

随机推荐

  1. 自学Python4.8-生成器(方式二:生成器表达式)

    自学Python之路-Python基础+模块+面向对象自学Python之路-Python网络编程自学Python之路-Python并发编程+数据库+前端自学Python之路-django 自学Pyth ...

  2. rt-thread 学习路线

    @2019-01-25 [小记] > BSP制作与使用 将板载资源.芯片外设全部制作BSP,做到使用时只需在 menuconfig 中配置即用

  3. 【php】php算法的一些实现

    1.生成一定范围内的数组,步长可以设置 function range($step = 10, $max = 100){ if ($step < 1 || $step > $max){ re ...

  4. Keepalived+Nginx搭建主从高可用并带nginx检测

    应用环境:部分时候,WEB访问量一般,或者测试使用,利用Keepalived给Nginx做高可用即可满足要求. 测试环境:   搭建步骤: 1. 安装软件 在Nginx-A和Nginx-B上: ~]# ...

  5. 使用Docker for Windows初体验

    https://www.baidu.com/link?url=61Kwadwh6h__2Vmjf7lAKVo1RjhsULAqERcMXYnYzkLKrRVpygwBJVnjultH8zbq& ...

  6. poj3179 Corral the Cows

    论水题与难题的差距:在于一个upper_bound 那么,这题一看就很显然了:因为答案满足二分性质所以我们二分. 然后我们再建造一个二维前缀和,每次判断的时候怎么办呢? 我先以为是贪心:选择以每个点为 ...

  7. 使用jquery.pjax实现SPA单页面应用

    前面文章介绍了前端路由简单实现和Pjax入门方面的文章,今天来分享一个单页面应用神器jquery.pjax.js. HTML 我们准备一个加载div#loading,默认隐藏,ajax请求的时候才显示 ...

  8. How MVC pattern Flows

    以上MVC流程中Model和View不存在依赖关系 以上MVC流程View和Model存在耦合关系(依赖关系越少越好)

  9. 使用WinForm Chart控件 制作饼装,柱状,折线图

    http://blog.csdn.net/dream2050csdn/article/details/53510340 chart控件的属性很多,主要用到Chart控件图表区域的属性有五个属性 1.A ...

  10. 关于苹果手机微信端 position: fixed定位top导航栏问题

    在移动端,position: fixed定位一般不被识别,或者在ios系统中,获取input焦点时,会导致position: fixed的top失效,下面是我验证过的方法,大家可以试试.<!do ...