顯示具有 Maven 標籤的文章。 顯示所有文章
顯示具有 Maven 標籤的文章。 顯示所有文章

2015年11月2日 星期一

[maven] profile - activation

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

profile 設定裡面除了 id, build 之外還有個蠻有用的設定

activation 可以用來設定啟用這個 profile 的條件 (哇喔~~~)

指定 JDK 1.4
  1. <activation>
  2. <jdk>1.4</jdk>
  3. </activation>

JDK 1.3~1.6前
  1. <activation>
  2. <jdk>[1.3,1.6)</jdk>
  3. </activation>

特定 OS
  1. <activation>
  2. <os>
  3. <name>Windows XP</name>
  4. <family>Windows</family>
  5. <arch>x86</arch>
  6. <version>5.1.2600</version>
  7. </os>
  8. </activation>

有 debug 這個 property
  1. <activation>
  2. <property>
  3. <name>debug</name>
  4. </property>
  5. </activation>

environment 設定成 test -Denvironment=test
  1. <activation>
  2. <property>
  3. <name>environment</name>
  4. <value>test</value>
  5. </property>
  6. </activation>

沒有某個檔案或資料夾
  1. <activation>
  2. <file>
  3. <missing>target/generated-sources/axistools/wsdl2java/org/apache/maven</missing>
  4. </file>
  5. </activation>

預設啟動
  1. <activation>
  2. <activeByDefault>true</activeByDefault>
  3. </activation>

2015年10月17日 星期六

[maven] profile 使用

最近專案在發佈的時候,需要把 war 檔案中的 config, jar 等檔案移出來的需求

看了一下 maven-war-plugin 的範例文件

把專案設定丟出來加些說明

1. 在 pom.xml 裡面增加 profiles 不同的 profile 可以適用不同環境的上版參數設定

2. profile 裡面主要有三個 plugin,設定大概如下方說明

3. mvn clean install -Dmaven.test.skip=true -Puat

-P 就是指定 profile 的意思

Eclipse version


threads 跟 skip Tests 都是自己加的 不需要可以自己移掉


--- plugin 示意

  •  maven-war-plugin : 
    • 處理 war 檔案包裝,包括檔案過濾、web.xml 指定、其他資源載入等
  • maven-compiler-plugin
    • java 編譯相關參數,設定編譯用參數,顯示提示等
  • maven-resource-plugin
    • 將設定檔案移動至指定位置

2015年8月11日 星期二

[Maven] 基本 plugin

mvn [<goal(s)>] [<phase(s)>]

goal: <plugin>:<goal>

-- goal --
archetype:generate
    http://maven.apache.org/archetype/maven-archetype-plugin/
help:help
 
compiler:compile

    http://maven.apache.org/plugins/maven-compiler-plugin/
war:war

    http://maven.apache.org/plugins/maven-war-plugin/
jar:jar

    http://maven.apache.org/plugins/maven-jar-plugin/
dependency:help

    http://maven.apache.org/plugins/maven-dependency-plugin/
source:help

    http://maven.apache.org/plugins/maven-source-plugin/

checkstyle:checkstyle

    http://maven.apache.org/plugins/maven-checkstyle-plugin/
pmd:pmd

    http://maven.apache.org/plugins/maven-pmd-plugin/

ant:ant

    http://maven.apache.org/plugins/maven-ant-plugin/
antrun:run
    http://maven.apache.org/plugins/maven-antrun-plugin/


tomcat6/7
    http://tomcat.apache.org/maven-plugin-2.2/context-goals.html
cargo (支援多種 container 發布)
    https://codehaus-cargo.github.io/cargo/Home.html

-- phase --
clean
compile
deploy
install
test
package

2013年9月13日 星期五

Maven專案設定

通常我們在開發的時候,會把專案切成幾個部分

例如前端呈現與後台邏輯,各自也可以有自己架構

前端呈現或許可以是單純html+javascript library

也可以用類似ZK這樣比較大型的framework

這時候我們一樣可以使用Maven來幫助我們做管理


首先 建立一個主專案 裡面的pom.xml設定
<project>
.
.
.
   <packaging>pom</packaging>
.
.
.
   <modules>
      <module>webProject</module>
      <module>serviceProject</module>   </modules>
.
.
.
</project>

有看到module嗎?我們可以直接在主專案資料夾裡面建立其他的maven專案

這樣當我們編譯主專案的時候,就會跟著依照module的名稱,去編譯其他的module囉

2013年6月19日 星期三

Maven lifecycle phase整理

Maven command format

  mvn <lifycyclePhase>

  mvn <plugin-prefix>:<goal>

  mvn <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>


Available lifecycle phases

validate,
initialize,
generate-sources, process-sources, generate-resources, process-resources,
compile,
process-classes,
generate-test-sources, process-test-sources, generate-test-resources, process-test-resources,
test-compile,
process-test-classes,
test,
prepare-package, package,
pre-integration-test, integration-test, post-integration-test,
verify,
install,
deploy,
pre-clean, clean, post-clean,
pre-site, site, post-site, site-deploy


2013年6月6日 星期四

Maven 清除下載失敗


Mac/Linux

find ~/.m2 -name "*.lastUpdated" -exec grep -q "Could not transfer" {} \; -print -exec rm {} \;


Windows

cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i

2012年12月16日 星期日

Maven 指令

mvn dependency:sources
    下載 source code

mvn help:describe -Dplugin=help -Dgoal=describe -Ddetail

pmd

mvn pmd:pmd -DtargetJdk=1.6

2012年8月19日 星期日

Maven Q&A

Maven

    http://maven.apache.org/index.html
    http://maven.apache.org/plugins/index.html

    Maven實在是個很方便的東西,管好了library寫程式的心情大悅 XDD
    目前都是用Eclipse所以也就很自然的用Eclipse的Plugin,又所以更自然的遇到了一些問題!!

調整預設的Compiler版本

    pom.xml <project> 裡面加入設定



自動把Maven library放進WEB-INF/lib資料夾

先在 project>build 中加入

 再到 project > build > plugins 裡面加入