parent pom 定義你的項目模型,包括構建方式,項目環境,項目依賴,輸出JavaDoc,發佈source源碼等等,怎樣去編寫一份parent pom,這裏是一個現成的並正在某些項目中使用到的:點擊查看GitHub源碼css
A best global parent pom file , you can use it in jar or war project as your maven parent pom settingjava
<parent> <groupId>com.peaceful</groupId> <artifactId>peaceful-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent>
project build coding:UTF-8
mysql
maven repositories:repo2
git
default profiles: dev
、test
、product
. The pom think project should has three running env or build env:dev、test、product. you can specify the environment by :github
`mvn -Penv[test][product] compile[deploy][jetty:run]`
The default env is dev, you can get the env value in pom by ${project.environment} and in Java code by invoke Application.getRunningMode()
web
buildnumber-maven-plugin:1.3 phase:validate desc:use timestamp as build version,you can get the version value by ${timestamp}
in pom.xml and get the value in Java code by invoke Application.getBuildVersion()
spring
maven-jar-plugin:2.6sql
maven-compiler-plugin:3.3json
maven-war-plugin:2.0.2api
maven-resources-plugin:2.7
maven-source-plugin:2.4 phase:deploy
maven-javadoc-plugin:2.9.1 phase:deploy
maven-surefire-plugin:2.7 desc: default skip test
yuicompressor-maven-plugin:1.5.0 desc:compress style file: .js .css
jetty-maven-plugin:8.1.8.v20121106 desc: start web project in jetty, default port 8888,you can change web port in your pom to override Settings
<properties> <jetty.stop.port>9999</jetty.stop.port> <jetty.run.port>8888</jetty.run.port> </properties>
log:slf4j log4j perf4j
test:junit
common tools:guava、commons-lang三、httpclient
json:fastjson
web:jstl、javaee-api
db:mysql、c3p0
framework:spring、springMvc、mybatis
Cooperate with the parent pom configuration files, can read building basic information, such as building time, version number, running environment of the project
The parent pom define 3 kinds of profile:dev
、test
、product
。If your project use the pom as parent pom,you need add peaceful-common-utils
dependency in your pom file.
<dependency> <groupId>com.peaceful</groupId> <artifactId>peaceful-common-utils</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
The peaceful-common-utils
will read your build info into application.properties.
Application.getVersion()
Application.getRunningMode() ... Application.isTest() Application.isProduct() Application.isDev()
# you need invoke Application.loadToJVM() when your application start Application.getRunningTime()