<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Terry.Li-彬

    虛其心,可解天下之問;專其心,可治天下之學;靜其心,可悟天下之理;恒其心,可成天下之業。

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
    一個Maven2工程的核心就是這一個pom.xml,它包含了你的工程詳細信息,如:版本、配置、依賴、測試、項目成員等等。學習maven2主要就是學習如何配置pom.xml。

    一個簡單的而完全可操作的pom.xml如下所示:

    <project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion> <!--maven2-->
    <groupId>ctzj_bss</groupId> <!-- 這個項目所屬組的id,一般是項目所在的公司或組織的域名 -->
    <artifactId>NRC</artifactId> <!-- 項目的id,和groupId一起組成這個項目的一個唯一id,以用在別的maven2工程中 -->
    <packaging>jar</packaging> <!-- 最后這個工程的打包類型,在這里是打成jar包 -->
    <version>1.0</version> <!-- 版本號 -->
    <name>kenan nrc batch</name> <!-- 項目名, 區別于artifactId-->
    <description>insert a nrc in kenan db</description> <!-- 項目描述,會出現在生成的工程站點上 -->
    <build> <!-- 項目的構建信息 -->
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <outputDirectory>target\classes</outputDirectory>
        <testOutputDirectory>target\test-classes</testOutputDirectory>
        <directory>target</directory> <!-- 構建后生成文件(jar,site等)所在位置 -->
    </build>
    <dependencies> <!-- 項目的依賴外接包,maven的優勢之一 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <reporting> <!-- 項目報表,有很多插件可供選擇 -->
        <outputDirectory>target/site</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
    </project>

    在你配置了你的pom文件后,你就可以使用如下命令來運行maven2

    mvn compiler:compile 編譯你的原文件
    mvn jar:jar 打包
    mvn site:site 生成項目站點


    接下來逐個介紹pom.xml的各個要素
    developor,organization and mail lit
    build
    dependencies
    reporting


    1.developor,organization and mail list

    可以在pom中加入開發人員列表,項目所屬組織信息,郵件列表,這些信息會出現在生成的項目站點上

    <organization>
        <name>CTZJ BSS</name>
    </organization>
    <developers>
        <developer>
            <name>Chen Lin</name>
            <organization>ZJHCsoft</organization>
            <email>chenlin@zjhcsoft.com</email>
        </developer>
    </developers>
    <mailingLists>
        <mailingList>
            <name>${pom.name} Dev List</name>
        </mailingList>
        <mailingList>
            <name>${pom.name} User List</name>
        </mailingList>
    </mailingLists>

    2. build

    配置項目的構建信息,主要有指定目錄,包括源代碼、測試源代碼、輸出目錄、資源目錄等.如果沒有特殊需求以上的pom已經足夠了

    3. dependencies

    配置項目要用到的jar包.自認為maven對jar包的管理是它的一個重要特色.下面是一個jar包的配置:

    <dependency>
        <groupId>concurrent</groupId>
        <artifactId>concurrent</artifactId>
        <version>1.3.4</version>
        <scope>compile</scope>
    </dependency>

    groupId: 沒有特定的含義,一般來自同一組織的jar包會有相同的groupId值
    artifactId: 這個jar的id,一般是這個jar包的名稱
    version: jar包的版本號,一般情況下,artifactId-version.jar就是這個jar包的文件名
    scope: 這個jar所影響的范圍,compile指它會在編譯源代碼時用到.還有test,provide,runtime等值

    如果你不知道jar包的groupId和artifactId,可以到http://www.mavenregistry.com/ 進行查詢

    一旦指定后,當你進行編譯時,它就會到你的本地資源庫

    另,如果你引入本地包,則需要先行將它安裝到本地資料庫(repository),使用如下命令

    mvn install:install-file -DgroupId=%groupId% -DartifactId=%artifactId% -DgeneratePom=true -Dfile=%file% -Dpackaging=jar -Dversion=%version%

    4. reporting

    通過使用相應的report plug-in可以生成各種各樣的report.如javadoc,junit test report,代碼檢查等

    常用的常見有

    <plugin>
        <groupId>org.apache.maven.plugins</groupId> <!--java doc -->
        <artifactId>maven-javadoc-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId> <!-- 代碼檢查 -->
        <artifactId>maven-checkstyle-plugin</artifactId>
        <configuration>
            <configLocation>config/sun_checks.xml</configLocation>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId> <!-- test 結果報表 -->
        <artifactId>surefire-report-maven-plugin</artifactId>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId> <!-- 源代碼的HTML化 -->
        <artifactId>jxr-maven-plugin</artifactId>
    </plugin>

    在maven的官方網站有可以找到更多的report plugin


    最后一個比較完整的pom.xml看起來像這樣:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <name>CutoverModule</name>
    <groupId>ctzj_batch</groupId>
    <artifactId>eai_cutover</artifactId>
    <url>http://134.98.83.137:8081/scarab/issues</url>
    <inceptionYear>2006</inceptionYear>
    <organization>
        <name>CTZJ BSS</name>
        <url>http://www.zjhcsoft.com</url>
    </organization>
    <version>1.0</version>
    <description>97 cutover batch module:invoke eai-adapter to update the phone number or value of
    c4/c5</description>
    <developers>
        <developer>
            <name>Chen Lin</name>
            <organization>ZJHCSoft</organization>
            <email>chenlin@zjhcsoft.com</email>
        </developer>
    </developers>
    <mailingLists>
        <mailingList>
            <name>${pom.name} Dev List</name>
         </mailingList>
    </mailingLists>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>test</testSourceDirectory>
        <outputDirectory>target\classes</outputDirectory>
        <testOutputDirectory>target\test-classes</testOutputDirectory>
        <directory>target</directory>
        <plugins>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.1</version>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.1</version>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.1.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.1</version>
        </plugin>
        </plugins>
    </build>
    <ciManagement>
        <system>continuum</system>
        <url>http://localhost:8080/continuum/servlet/continuum</url>
    </ciManagement>
    <scm>
        <connection>scm:local|E:/eclipseworkshop|EAIBatch</connection>
    </scm>
    <dependencies>
        <dependency>
            <groupId>ctzj_batch</groupId>
            <artifactId>Eaiadapter</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>ctzj_batch</groupId>
            <artifactId>ta</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>ctzj_batch</groupId>
            <artifactId>grnds-common</artifactId>
            <version>4.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>concurrent</groupId>
            <artifactId>concurrent</artifactId>
            <version>1.3.4</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <reporting>
        <outputDirectory>target/site</outputDirectory>
        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <configuration>
                <configLocation>config/sun_checks.xml</configLocation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>surefire-report-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jxr-maven-plugin</artifactId>
        </plugin>
        </plugins>
    </reporting>
    </project>
    posted on 2008-01-10 19:46 禮物 閱讀(1449) 評論(0)  編輯  收藏 所屬分類: maven2
    主站蜘蛛池模板: 免费电视剧在线观看| a级毛片在线免费观看| 日韩免费福利视频| 一区二区免费视频| 黄网站色视频免费观看45分钟 | 亚洲av中文无码乱人伦在线咪咕 | 四虎必出精品亚洲高清| 亚洲v国产v天堂a无码久久| xx视频在线永久免费观看| 人妻免费一区二区三区最新| 亚洲成av人片天堂网老年人| 精品无码无人网站免费视频| 一级做a爰黑人又硬又粗免费看51社区国产精品视 | 亚洲色图.com| 亚洲成A∨人片在线观看无码| 精品亚洲综合久久中文字幕| 啊灬啊灬别停啊灬用力啊免费看| 最近中文字幕无吗免费高清| 又粗又大又黑又长的免费视频| 一级毛片不卡片免费观看| 国产免费一区二区视频| 在线观看免费无码视频| a毛片在线免费观看| 91精品免费不卡在线观看| 99久久综合精品免费| 久久精品私人影院免费看| 久久aa毛片免费播放嗯啊| 免费福利视频导航| 好大好硬好爽免费视频| 国产精品免费一级在线观看| 免费乱码中文字幕网站| 亚洲色婷婷六月亚洲婷婷6月| 国产亚洲情侣一区二区无码AV| 在线a亚洲v天堂网2019无码| 亚洲AV日韩AV永久无码久久| 亚洲成电影在线观看青青| 美女黄色免费网站| 最近高清中文字幕免费| 亚洲精品NV久久久久久久久久| 亚洲福利在线观看| 亚洲国产精品无码久久久秋霞1 |