日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Maven快速入門

 pablo3518 2007-07-27
轉(zhuǎn)載聲明:版權(quán)規(guī)文章原創(chuàng)作者所有
轉(zhuǎn)載時間:2007年07月27日
轉(zhuǎn)載作者:pablo3518
 
 

Maven快速入門

創(chuàng)建快速啟動項目

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app

編譯

mvn compile

測試

mvn test

如果只是編譯測試源文件,而不啟動測試:

mvn test-compile

打包

mvn package

安裝到本地Repository

mvn install

Maven會自動查找測試文件,尋找的模式為:

默認包括的測試文件有:

  • **/*Test.java
  • **/Test*.java
  • **/*TestCase.java

默認排除的測試文件有:

  • **/Abstract*Test.java
  • **/Abstract*TestCase.java

 

創(chuàng)建項目網(wǎng)站

mvn site

 

清理

mvn clean

 

為項目生成IntelliJ IDEA描述符,可以在一個已經(jīng)存在的IDEA項目上進行,會更新設置而不是從零開始。

mvn idea:idea

 

如何使用插件

示例如下:

<build>

  <plugins>

    <plugin>

      <groupId>org.apache.maven.plugins</groupId>

      <artifactId>maven-compiler-plugin</artifactId>

      <configuration>

        <source>1.5</source>

        <target>1.5</target>

      </configuration>

    </plugin>

  </plugins>

</build>

 

如何在Jar中包含資源

把資源放置在${basedir}/src/main/resources目錄中即可。測試用例所需資源的路徑是${basedir}/src/test/resources。

 

如何過濾資源文件

有時候資源文件需要構(gòu)建時刻才能提供的值,為了達到這個目的,在資源文件中添加${<property name>}這樣的引用。這些屬性可以來自pom.xml,settings.xml,其它的屬性文件或是系統(tǒng)屬性。

按照如下方式修改pom.xml

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>

按如下使用pom.xml中的值:

# application.properties
application.name=${pom.name}
application.version=${pom.version}

如果是使用其它的屬性文件:

<build>
    <filters>
      <filter>src/main/filters/filter.properties</filter>
    </filters>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>

也可以把這些屬性寫在pom.xml中:

<properties>
    <my.filter.value>hello</my.filter.value>
  </properties>

同樣可以是Java的系統(tǒng)屬性,或是通過-D傳入命令行參數(shù)。

 

如何使用外部依賴

pom.xml中的dependencies一節(jié)中列出了所需的全部外部依賴。為了定義外部依賴,需要定義至少4個內(nèi)容:groupId, artifactId, version, scope。Scope可以是testcompileruntime。Maven會自動從一個遠程的Repository下載所需的依賴。

 

如何部署jar到自己的遠程repository

pom.xml中添加如下內(nèi)容:

<distributionManagement>

    <repository>

      <id>mycompany-repository</id>

      <name>MyCompany Repository</name>

      <url>scp://repository.mycompany.com/repository/maven2</url>

    </repository>

  </distributionManagement>

 

同樣在用戶的settings.xml中也要定義服務器:

<settings>

  <servers>

    <server>

      <id>mycompany-repository</id>

      <username>jvanzyl</username>

      <!-- Default value is ~/.ssh/id_dsa -->

      <privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa)

      <passphrase>my_key_passphrase</passphrase>

    </server>

  </servers>

</settings>

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多