一、maven
1、構(gòu)建目錄結(jié)構(gòu)
mkdir -p src/main/java/hello
2介袜、源代碼放入 src/main/java/hello痹兜,并在根目錄下添加 pom.xml
3蛮粮、構(gòu)建
mvn compile
// 在target/classes下生成 .class 文件
mvn package
// 在target下面生成 .jar/.war 文件
mvn install
// 相當(dāng)于 mvn package 之后在放入到本地依賴庫中
4益缎、依賴管理
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>
scope的取值:compile、provided然想、test莺奔。
5、寫單測
mkdir -p src/test/java/hello/
mvn test
// 運(yùn)行單測
二变泄、auto-config 多環(huán)境自動(dòng)打包
auto-config主要涉及的文件有以下部分:
- auto-config.xml
- antx.properties.vm
- antx.property
1弊仪、auto-config.xml
定義那些字符需要替換,他們的默認(rèn)值是什么
需要在 webapp\META-INF\autoconf\
目錄下
<config description="console config">
<group name="common config">
<property name="config.redis.host"/>
</group>
<script>
<generate template="antx.properties.vm" destfile="WEB-INF/classes/antx.properties" charset="UTF-8"/>
</script>
</config>
2杖刷、antx.properties.vm
定義模板文件, 模板文件沒有特別的格式
config.redis.host=${config_redis_host}
3励饵、antx.properties
antx.properties.vm 中的占位符被真實(shí)值替換后生成的文件
4、spring 配置文件
<context:property-placeholder location="classpath:antx.properties"/>