Maven學習--------基礎2


繼續學習Maven。

4.2 變量

1) 問:怎樣使用變量替換?項目中的某個配置文件比方jdbc.properties使用了一些pom中的變量,怎樣在公佈中使用包括真實內容的終於結果文件?

答:使用資源過濾功能,比方:css

< project >
    ... 
     < properties >
         < jdbc.driverClassName >com.mysql.jdbc.Driver </ jdbc.driverClassName >
         < jdbc.url >jdbc:mysql://localhost:3306/development_db </ jdbc.url >
         < jdbc.username >dev_user </ jdbc.username >
         < jdbc.password >s3cr3tw0rd </ jdbc.password >
     </ properties >
    ... 
     < build >
         < resources >
             < resource >
                 < directory >src/main/resources </ directory >
                 < filtering >true </ filtering >
             </ resource >
         </ resources >
     </ build >
    ... 
     < profiles >
         < profile >
             < id >production </ id >
             < properties >
                 < jdbc.driverClassName >oracle.jdbc.driver.OracleDriver </ jdbc.driverClassName >
                 < jdbc.url >jdbc:oracle:thin:@proddb01:1521:PROD </ jdbc.url >
                 < jdbc.username >prod_user </ jdbc.username >
                 < jdbc.password >s00p3rs3cr3t </ jdbc.password >
             </ properties >
         </ profile >
     </ profiles >
</ project >

2) 問: maven-svn-revision-number-plugin 插件說明

答: maven-svn-revision-number-plugin 可以從 SVN 中獲取版本,並將其變成環境變量,交由其它插件或者profile使用,具體幫助在這裏 。通常和resource的filter機制同一時候使用html

< plugins >
     < plugin >
         < groupId >com.google.code.maven-svn-revision-number-plugin </ groupId >
         < artifactId >maven-svn-revision-number-plugin </ artifactId >
         < version >1.3 </ version >
         < executions >
             < execution >
                 < goals >
                     < goal >revision </ goal >
                 </ goals >
             </ execution >
         </ executions >
         < configuration >
             < entries >
                 < entry >
                     < prefix >prefix </ prefix >
                 </ entry >
             </ entries >
         </ configuration >
     </ plugin >
</ plugins >

這段代碼負責把resource文件裏的內容替換成適當內容java

repository = ${prefix.repository}
path = ${prefix.path}
revision = ${prefix.revision}
mixedRevisions = ${prefix.mixedRevisions}
committedRevision = ${prefix.committedRevision}
status = ${prefix.status}
specialStatus = ${prefix.specialStatus}

3)個人程序有些單元測試有錯誤。怎樣忽略測試步驟?

有好幾種方法都可以實現跳過單元測試步驟。一種是給mvn添加命令行參數 -Dmaven.test.skip=true 或者 -DskipTests=true 。第二種是給surefire插件添加參數。例如如下:mysql

<span class="kwrd"><</span><span class="html">project</span><span class="kwrd">></span>
  [...]
  <span class="kwrd"><</span><span class="html">build</span><span class="kwrd">></span>
    <span class="kwrd"><</span><span class="html">plugins</span><span class="kwrd">></span>
      <span class="kwrd"><</span><span class="html">plugin</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">groupId</span><span class="kwrd">></span>org.apache.maven.plugins<span class="kwrd"></</span><span class="html">groupId</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">artifactId</span><span class="kwrd">></span>maven-surefire-plugin<span class="kwrd"></</span><span class="html">artifactId</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">version</span><span class="kwrd">></span>2.8<span class="kwrd"></</span><span class="html">version</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">configuration</span><span class="kwrd">></span>
          <span class="kwrd"><</span><span class="html">skipTests</span><span class="kwrd">></span>true<span class="kwrd"></</span><span class="html">skipTests</span><span class="kwrd">></span>
        <span class="kwrd"></</span><span class="html">configuration</span><span class="kwrd">></span>
      <span class="kwrd"></</span><span class="html">plugin</span><span class="kwrd">></span>
    <span class="kwrd"></</span><span class="html">plugins</span><span class="kwrd">></span>
  <span class="kwrd"></</span><span class="html">build</span><span class="kwrd">></span>
  [...]
<span class="kwrd"></</span><span class="html">project</span><span class="kwrd">></span>
4) 假設僅僅想執行單個測試用例,是否能實現?

可以,執行時候添加命令行參數 -Dtest=MyTest 就能夠,當中MyTest是所需要執行的單元測試用例名稱,但是不需要包括package部分。c++

4.3 編譯

1) 問:怎樣給插件指派參數?比方我要設置一些編譯參數

答:下面內容設定編譯器編譯java1.5的代碼sql

< project >
    ... 
     < build >
        ... 
         < plugins >
             < plugin >
                 < artifactId >maven-compiler-plugin </ artifactId >
                 < configuration >
                     < source >1.5 </ source >
                     < target >1.5 </ target >
                 </ configuration >
             </ plugin >
         </ plugins >
        ... 
     </ build >
    ... 
</ project >

要設置其它插件的參數也可以,請參考相應插件的幫助信息
2) 問:個人文件夾是非標準的文件夾結構。怎樣設置讓maven支持?

答:指定source文件夾和test-source文件夾就能夠。apache

< build >
     < directory >target </ directory >
     < sourceDirectory >src </ sourceDirectory >
     < scriptSourceDirectory >js/scripts </ scriptSourceDirectory >
     < testSourceDirectory >test </ testSourceDirectory >
     < outputDirectory >bin </ outputDirectory >
     < testOutputDirectory >bin </ testOutputDirectory >
</ build >

這個樣例把源碼設置成了src文件夾,測試代碼在test文件夾,因此輸出到bin文件夾。

這裏要注意,directory假設也設置成bin文件夾的話,maven打包的時候會引發死循環,因爲directory是所有工做存放的地方。默認包括outputDirectory定義的文件夾在內。oracle

3) 我源碼是UTF8格式的,我怎樣在maven中指定?

設置一個變量就能夠eclipse

< project >
    ... 
     < properties >
         < project.build.sourceEncoding >UTF-8 </ project.build.sourceEncoding >
     </ properties >
    ... 
</ project >
{color:blue}以上是官方給出的解決方式。但是通過嘗試這樣僅僅能影響到resource處理時候的編碼{color},真正實用的是例如如下配置:
{code:xml}
<build>
  ...
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <encoding>UTF-8</encoding>
      </configuration>
    </plugin>
  ...
</build>
{code}
. 問:個人項目除了main/java文件夾以外。還加了其它的c++文件夾,想要一併編譯,怎樣作?
答:使用native插件,詳細配置方法參考[http://mojo.codehaus.org/maven-native/native-maven-plugin/]
{code:xml}
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
</plugin>    
{code}
. 問:我想要把project的所有依賴的jar都一塊兒打包,怎麼辦?
答:首先改動maven的配置文件,給maven-assembly-plugin添加一個jar-with-dependencies的描寫敘述。

{code:xml}
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
{code}
而後使用命令打包就能夠:
mvn assembly:assembly
. 問:我想把main/scripts中的內容一塊兒打包公佈,怎樣作?
答:在pom中配置額外的資源文件夾。假設需要的話。還可以指定資源文件夾的輸出位置
{code:xml}
<build>
  ...
  <resources>
    <resource>
      <filtering>true</filtering>
      <directory>src/main/command</directory>
      <includes>
        <include>run.bat</include>
        <include>run.sh</include>
      </includes>
      <targetPath>/abc</targetPath>
    </resource>
    <resource>
      <directory>src/main/scripts</directory>
    </resource>
  </resources>
  ...
</build>
{code}
. 問:我有多個源碼文件夾,但是maven僅僅支持一個main src和一個test src,怎麼辦?
答:使用另一個插件,並仿照例如如下配置pom
{code:xml}
<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/config/java</source>
                <source>src/main/java</source>
                <source>src/member/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
{code}
. 問:個人源碼文件夾中有一部分文件我不想讓maven編譯,怎麼作?
答:使用一個maven插件,而後使用includes和excludes。

同理。也可以處理資源的過濾。ssh

{code:xml}
<build>
  <sourceDirectory>http://www.cnblogs.com/src/java</sourceDirectory>
  <plugins>
    <plugin>
      <groupId>com.sun.enterprise</groupId>
      <artifactId>hk2-maven-plugin</artifactId>
      <configuration>
        <includes>
          <include>com/sun/logging/LogDomains.*</include>
          <include>com/sun/enterprise/util/OS.java</include>
          <include>com/sun/enterprise/util/io/FileUtils.java</include>
          <include>com/sun/enterprise/util/zip/**</include>
          <include>com/sun/enterprise/util/i18n/**</include>
          <include>com/sun/enterprise/deployment/backend/IASDeploymentException.java</include>
        </includes>
        <excludes>
          <exclude>com/sun/enterprise/config/ConfigBeansFactory.java</exclude>
          <exclude>com/sun/enterprise/config/clientbeans/**</exclude>
        </excludes>
      </configuration>
    </plugin>
  </plugins>
  <resources>
    <resource>
      <directory>http://www.cnblogs.com/src/java</directory>
      <includes>
        <include>**/*.properties</include>
      </includes>
    </resource>
  </resources>
</build>
{code}
. 問:個人項目是一個純的html組成的項目,沒有不論什麼的java代碼,怎麼跳過編譯過程?
答:配置例如如下
{code:xml}
<build>
  <sourceDirectory>src/java</sourceDirectory>
  <plugins>
    <plugin>
    <groupId>com.sun.enterprise</groupId>
    <artifactId>hk2-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>
{code}
. 問:個人project裏用hibernate,想在編譯時候本身主動生成ddl,怎樣作?
答:加入插件
hibernate3-maven-plugin
。依照例如如下配置:
{code:xml}
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>hibernate3-maven-plugin</artifactId>
          <version>2.1</version>
          <configuration>
            <components>
              <component>
                <name>hbm2ddl</name>
                <implementation>annotationconfiguration</implementation>
              </component>
            </components>
          </configuration>
          <dependencies>
            <dependency>
              <groupId>hsqldb</groupId>
              <artifactId>hsqldb</artifactId>
              <version>${hsqldb.version}</version>
            </dependency>
          </dependencies>
        </plugin>
{code}
. 問:我能用maven支持eclipse RCP項目嗎?

答:固然可以,你可以使用插件 Tycho,具體內容可以參考這裏[http://mattiasholmqvist.se/2010/02/building-with-tycho-part-1-osgi-bundles/].

 <plugin>
  <groupid>org.sonatype.tycho</groupid>
  <artifactid>target-platform-configuration</artifactid>
  <version>0.7.0</version>
  <configuration>
    <resolver>p2</resolver>
  </configuration>
</plugin>
另外。老牌的pde-maven-plugin就不要用了,已經好幾年沒見更新了。

4.4 ant互動

1) 怎樣在maven編譯時候執行ant腳本?

使用專門的antrun插件,並且在target標籤內部增長ant的代碼

      <span class="kwrd"><</span><span class="html">plugin</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">artifactId</span><span class="kwrd">></span>maven-antrun-plugin<span class="kwrd"></</span><span class="html">artifactId</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">version</span><span class="kwrd">></span>1.6<span class="kwrd"></</span><span class="html">version</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">executions</span><span class="kwrd">></span>
          <span class="kwrd"><</span><span class="html">execution</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">phase</span><span class="kwrd">></span> <span class="rem"><!-- 生命週期階段 --></span> <span class="kwrd"></</span><span class="html">phase</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">configuration</span><span class="kwrd">></span>
              <span class="kwrd"><</span><span class="html">target</span><span class="kwrd">></span>
                <span class="rem"><!-- 增長target內部的代碼 --></span>
              <span class="kwrd"></</span><span class="html">target</span><span class="kwrd">></span>
            <span class="kwrd"></</span><span class="html">configuration</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">goals</span><span class="kwrd">></span>
              <span class="kwrd"><</span><span class="html">goal</span><span class="kwrd">></span>run<span class="kwrd"></</span><span class="html">goal</span><span class="kwrd">></span>
            <span class="kwrd"></</span><span class="html">goals</span><span class="kwrd">></span>
          <span class="kwrd"></</span><span class="html">execution</span><span class="kwrd">></span>
        <span class="kwrd"></</span><span class="html">executions</span><span class="kwrd">></span>
      <span class="kwrd"></</span><span class="html">plugin</span><span class="kwrd">></span>

2)怎樣在ant腳本中引用maven的classpath?

maven給每一個依賴都生成了一個屬性,格式爲"groupId:artifactId[:classifier]:type",比方,假設一下樣例就顯示依賴的org.apache.common-util的jar文件路徑

<span class="kwrd"><</span><span class="html">echo</span> <span class="attr">message</span><span class="kwrd">="Dependency JAR Path: ${org.apache:common-util:jar}"</span><span class="kwrd">/></span> 

另外,maven還提早定義了四個classpath的引用。他們是

  • maven.compile.classpath
  • maven.runtime.classpath
  • maven.test.classpath
  • maven.plugin.classpath

3)怎樣使用antrun插件執行外部的build文件?

很是easy,直接在antrun裏邊使用ant指令就能夠。例如如下:

<span class="kwrd"><</span><span class="html">plugin</span><span class="kwrd">></span>
    <span class="kwrd"><</span><span class="html">groupId</span><span class="kwrd">></span>org.apache.maven.plugins<span class="kwrd"></</span><span class="html">groupId</span><span class="kwrd">></span>
    <span class="kwrd"><</span><span class="html">artifactId</span><span class="kwrd">></span>maven-antrun-plugin<span class="kwrd"></</span><span class="html">artifactId</span><span class="kwrd">></span>
    <span class="kwrd"><</span><span class="html">version</span><span class="kwrd">></span>1.6<span class="kwrd"></</span><span class="html">version</span><span class="kwrd">></span>
    <span class="kwrd"><</span><span class="html">executions</span><span class="kwrd">></span>
        <span class="kwrd"><</span><span class="html">execution</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">id</span><span class="kwrd">></span>compile<span class="kwrd"></</span><span class="html">id</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">phase</span><span class="kwrd">></span>compile<span class="kwrd"></</span><span class="html">phase</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">configuration</span><span class="kwrd">></span>
                <span class="kwrd"><</span><span class="html">target</span><span class="kwrd">></span>
                    <span class="rem"><!-- 同一時候傳遞內置的classpath給外部ant文件 --></span>
                    <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="compile_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.compile.classpath"</span><span class="kwrd">/></span>
                    <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="runtime_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.runtime.classpath"</span><span class="kwrd">/></span>
                    <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="test_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.test.classpath"</span><span class="kwrd">/></span>
                    <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="plugin_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.plugin.classpath"</span><span class="kwrd">/></span>
    
                    <span class="kwrd"><</span><span class="html">ant</span> <span class="attr">antfile</span><span class="kwrd">="${basedir}/build.xml"</span><span class="kwrd">></span>
                        <span class="kwrd"><</span><span class="html">target</span> <span class="attr">name</span><span class="kwrd">="test"</span><span class="kwrd">/></span>
                    <span class="kwrd"></</span><span class="html">ant</span><span class="kwrd">></span>
                <span class="kwrd"></</span><span class="html">target</span><span class="kwrd">></span>
            <span class="kwrd"></</span><span class="html">configuration</span><span class="kwrd">></span>
            <span class="kwrd"><</span><span class="html">goals</span><span class="kwrd">></span>
                <span class="kwrd"><</span><span class="html">goal</span><span class="kwrd">></span>run<span class="kwrd"></</span><span class="html">goal</span><span class="kwrd">></span>
            <span class="kwrd"></</span><span class="html">goals</span><span class="kwrd">></span>
        <span class="kwrd"></</span><span class="html">execution</span><span class="kwrd">></span>
    <span class="kwrd"></</span><span class="html">executions</span><span class="kwrd">></span>
<span class="kwrd"></</span><span class="html">plugin</span><span class="kwrd">></span>
. 問:怎樣在ant中使用maven的功能?
答:使用ant的[maven task|http://maven.apache.org/ant-tasks/index.html]。只是僅僅有ant 1.6以上和jdk 1.5環境才支持。

h4. 測試相關

. 問:怎樣忽略某個階段的結果?比方單元測試不必定要全正確
答:給插件添加testFailureIgnore參數。並設置爲false。

假設要屏蔽該階段,則用

<skip>true</skip>
{code:xml}
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <testFailureIgnore>true</testFailureIgnore>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
{code}
. 問:我怎樣在maven中增長PMD,CheckStyle,JDepend等檢查功能?
答:增長PMD檢查。下面代碼假設在
reporting
節點中增長則在
mvn site
中運行。假設在
build
節點中增長。則在build的時候本身主動執行檢查。具體配置參考[pmd插件使用說明|http://maven.apache.org/plugins/maven-pmd-plugin/]
{code:xml}
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>2.5</version>
      </plugin>
    </plugins>
{code}
增長 checkstyle 檢查。具體配置參考[checkstyle插件使用說明|http://maven.apache.org/plugins/maven-checkstyle-plugin/],相同注意放置在reporting和build節點中的差異(所有報表類插件都要相同注意):
{code:xml}
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.5</version>
      </plugin>
{code}
增長 simian 的支持。simian是一個支持代碼類似度檢查的工具,眼下有maven插件,也有checkstyle的插件。

它不只可以檢查java,甚至可以支持文本文件的檢查。

具體幫助信息參考[這裏|http://www.redhillconsulting.com.au/products/simian/]。simian 的 maven插件在[這裏|http://mojo.codehaus.org/simian-report-maven-plugin/introduction.html]

{code:xml}
      <build>
         <plugins>
            <plugin>
               <groupId>org.codehaus.mojo</groupId>
               <artifactId>simian-maven-plugin</artifactId>
               <version>1.6.1</version>
            </plugin>
         </plugins>
         ...
      </build>
{code}
增長 jdepend 檢查,具體配置參考[jdepend使用說明|http://mojo.codehaus.org/jdepend-maven-plugin/],
{code:xml}
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jdepend-maven-plugin</artifactId>
        <version>2.0-beta-2</version>
      </plugin>
{code}
增長 findbugz 檢查,具體配置參考[findbugz使用說明|http://mojo.codehaus.org/findbugs-maven-plugin/usage.html],
{code:xml}
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>2.0.1</version>
      </plugin>
{code}
增長javadoc生成,具體配置參考[javadoc usage|http://maven.apache.org/plugins/maven-javadoc-plugin/usage.html]
{code:xml}
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.7</version>
        <configuration>
          ...
        </configuration>
      </plugin>
{code}
增長 jxr 支持。JXR是一個生成java代碼交叉引用和源碼的html格式的工具。具體配置信息參考[jxr usage|http://maven.apache.org/plugins/maven-jxr-plugin/]。

注意,jxr沒有必要在build階段執行。

{code:xml}
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jxr-plugin</artifactId>
        <version>2.1</version>
      </plugin>
    </plugins>
  </reporting>
{code}
增長 Cobertura 支持,它是一個代碼覆蓋率工具,可以用來評估具備對應測試的源碼的比率。具體幫助在[這裏|http://mojo.codehaus.org/cobertura-maven-plugin/index.html]。另一個功能類似的軟件是[EMMA|http://emma.sourceforge.net/samples.html],具體的幫助在[這裏|http://mojo.codehaus.org/emma-maven-plugin/usage.html]。兩個產品的比較文章在[這裏|http://www.topcoder.com/tc?

module=Static&d1=features&d2=030107]。我的傾向於都要用,因爲給出的指標不同。都有參考做用。

{code:xml|title=Cobertura }
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <check>
            <branchRate>85</branchRate>
            <lineRate>85</lineRate>
            <haltOnFailure>true</haltOnFailure>
            <totalBranchRate>85</totalBranchRate>
            <totalLineRate>85</totalLineRate>
            <packageLineRate>85</packageLineRate>
            <packageBranchRate>85</packageBranchRate>
            <regexes>
              <regex>
                <pattern>com.example.reallyimportant.*</pattern>
                <branchRate>90</branchRate>
                <lineRate>80</lineRate>
              </regex>
              <regex>
                <pattern>com.example.boringcode.*</pattern>
                <branchRate>40</branchRate>
                <lineRate>30</lineRate>
              </regex>
            </regexes>
          </check>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>clean</goal>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
{code}
{code:xml|title=EMMA}
  <reporting>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>emma-maven-plugin</artifactId>
        <version>1.0-alpha-3-SNAPSHOT</version>
      </plugin>
      ...
    </plugins>
    ...
  </reporting>
{code}
加入 javaNCSS 插件。它是一個java代碼的度量工具,具體參考在[這裏|http://mojo.codehaus.org/javancss-maven-plugin/]。
{code:xml}
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>javancss-maven-plugin</artifactId>
        <version>2.0-beta-2</version>
      </plugin>
    </plugins>
  </reporting>
{code}
h4. profile相關
. 問:profile能夠設置爲某個變量不存在的條件下激活?
答:使用。前綴,請看演示樣例:
{code:xml}
<activation>
        <property>
          <name>!environment.type</name>
        </property>
      </activation>
{code}
h4. 部署相關
. 問:其它部署到server的方式和配置怎麼配?
答:本文摘自 [http://blog.csdn.net/zyxnetxz/archive/2009/05/18/4199348.aspx]{panel} *Distribution Management* 用於配置分發管理。配置對應的產品公佈信息,主要用於公佈,在運行mvn deploy後表示要公佈的位置 *# 配置到文件系統
{code:xml}
<distributionManagement>
  <repository>
    <id>proficio-repository<id>
    <name>Proficio Repository<name>
    <url>file://${basedir}/target/deploy<url>
  <repository>
<distributionManagement>
{code}
*# 使用ssh2配置
{code:xml}
<distributionManagement>
  <repository>
    <id>proficio-repository<id>
    <name>Proficio Repository<name>
    <url>scp://sshserver.yourcompany.com/deploy<url>
  <repository>
<distributionManagement>
{code}
*# 使用sftp配置
{code:xml}
<distributionManagement>
  <repository>
    <id>proficio-repositoryi<d>
    <name>Proficio Repository<name>
    <url>sftp://ftpserver.yourcompany.com/deploy<url>
  <repository>
<distributionManagement>
{code}
*# 使用外在的ssh配置編譯擴展用於指定使用wagon外在ssh提供,用於提供你的文件到對應的遠程server。
{code:xml}
<distributionManagement>
  <repository>
    <id>proficio-repository<id>
    <name>Proficio Repository<name>
    <url>scpexe://sshserver.yourcompany.com/deploy<url>
  <repository>
<distributionManagement>
<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon<groupId>
      <artifactId>wagon-ssh-external<artifactId>
      <version>1.0-alpha-6<version>
    <extension>
  <extensions>
<build>
{code}
*# 使用ftp配置
{code:xml}
<distributionManagement>
  <repository>
    <id>proficio-repository<id>
    <name>Proficio Repository<name>
    <url>ftp://ftpserver.yourcompany.com/deploy<url>
  <repository>
<distributionManagement>
<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagongroupId>
      <artifactId>wagon-ftpartifactId>
      <version>1.0-alpha-6version>
    <extension>
  <extensions>
<build>
{code}
{panel} h4. 插件配置
. 問:我用maven輸出site,怎樣設置輸出爲utf8編碼?
答: 配置site插件的編碼設置
{code:xml}
...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-site-plugin</artifactId>
    <version>2.0-beta-6</version>
    <configuration>
      <outputEncoding>UTF-8</outputEncoding>
    </configuration>
  </plugin>
  ...
{code}
 
 
 
本文借鑑與http://aiape.iteye.com/blog/1455420
相關文章
相關標籤/搜索