posts - 6,  comments - 15,  trackbacks - 0
               摘要: 使用maven2 構(gòu)建 Webapp應(yīng)用程序
          基于以下框架:spring,hibernate,webwork.2.2.2  閱讀全文
          posted @ 2006-04-21 10:09 jbob 閱讀(2618) | 評(píng)論 (6)編輯 收藏
          13 jar包依賴(lài)
          我們?cè)趍vn install后在local repo中生成的jar包也可以被其他項(xiàng)目所引用
          <dependency>
          ??????
          <groupId>com.mycompany.app</groupId>
          ??????
          <artifactId>my-app</artifactId>
          ??????
          <version>1.0-SNAPSHOT</version>
          ??????
          <scope>compile</scope>
          </dependency>
          注意scope,這里是compile,如果使用junit,scope是test.

          舉例說(shuō)明
          如果我們的project需要用到log4j包,那么我們可以先google--"site:www.ibiblio.org maven2 log4j".
          Index of /maven2/log4j/log4j? 下面有maven-metadata.xml 描述了groupId,artifactId,version等等。
          獲取了這些信息之后,你就可以在pom.xml中添加依賴(lài)了
          <dependency>
          ??????
          <groupId>log4j</groupId>
          ??????
          <artifactId>log4j</artifactId>
          ??????
          <version>1.2.12</version>
          ??????
          <scope>compile</scope>
          </dependency>

          14 如何發(fā)布我的jar包到我的remote repository
          你需要在setting.xml中間設(shè)置server
          <servers>
          ????
          <server>
          ??????
          <id>mycompany-repository</id>
          ??????
          <username>jvanzyl</username>
          ??????
          <!--?Default?value?is?~/.ssh/id_dsa?-->
          ????
          <privateKey>/path/to/identity</privateKey>????????
          ??????? ?
          <passphrase>my_key_passphrase</passphrase>
          ????
          </server>
          </servers>
          然后在pom.xml中設(shè)置遠(yuǎn)程url
          <distributionManagement>
          ????
          <repository>
          ??????
          <id>mycompany-repository</id>
          ??????
          <name>MyCompany?Repository</name>
          ?????
          <url>scp://repository.mycompany.com/repository/maven2</url>
          ????
          </repository>
          ??
          </distributionManagement>
          posted @ 2006-03-28 20:07 jbob 閱讀(1496) | 評(píng)論 (4)編輯 收藏

          9 安裝[install]
          mvn install
          會(huì)將package之后的jar包c(diǎn)opy到
          <local-repository>/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.jar

          10 其他
          mvn site
          ?注意:還可以deploy site
          ?在pom.xml中加入

          ? < distributionManagement >
          ???
          < site >
          ?????
          < id > website </ id > ???
          ?????? ?
          < url > scp://www.mycompany.com/www/docs/project/ </ url >
          ???
          </ site >
          ?
          </ distributionManagement >


          當(dāng)然你需要設(shè)置server
          mvn site-deploy
          mvn clean
          mvn idea:idea [為IDE工具idea生成項(xiàng)目文件]

          11 Resource
          ${basedir}/src/main/resources都會(huì)編譯到j(luò)ar文件中
          而${basedir}/src/main/resources 下的內(nèi)容會(huì)直接位于jar文件的頂部
          測(cè)試用資源文件-> ${basedir}/src/test/resources
          引用時(shí)參照此例:
          InputStream is = getClass().getResourceAsStream( "/test.properties" );
          文件位于 ${basedir}/src/test/resources/test.properties。

          12 如何filter我們的資源文件
          在pom.xml中修改:

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


          因?yàn)樵瓉?lái)默認(rèn)的filter為false所以要加上上面的代碼
          e.g
          我們?cè)趕rc/main/resources下面建立application.properties文件
          ?# application.properties
          ?application.name=${pom.name}
          ?application.version=${pom.version}
          運(yùn)行:mvn process-resources
          在target/classes下面,
          application.properties:
          ?# application.properties
          ?application.name=Maven Quick Start Archetype
          ?application.version=1.0-SNAPSHOT
          這就是所謂的filter.
          當(dāng)然filter還可以用其他的外部文件,不一定來(lái)自pom.xml[ ${pom.name} ]以及setting.xml[ ${settings.localRepository }]
          e.g
          src/main/filters/filter.properties
          ?# filter.properties
          ?my.filter.value=hello!
          pom.xml

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


          # application.properties
          application.name=${pom.name}
          application.version=${pom.version}
          message=${my.filter.value}
          這樣在運(yùn)行mvn process-resources 會(huì)得到類(lèi)似的效果。

          當(dāng)然我們也可以直接在pom.xml中定義:

          < build >
          ????
          < resources >
          ??????
          < resource >
          ????????
          < directory > src/main/resources </ directory >
          ????????
          < filtering > true </ filtering >
          ??????
          </ resource >
          ????
          </ resources >
          ??
          </ build >
          ??
          < properties >
          ????
          < my .filter.value > hello </ my.filter.value >
          ??
          </ properties >


          效果同樣,這樣就不需要外部文件了

          另外filter還可以來(lái)自系統(tǒng)設(shè)置以及可以自定義:
          # application.properties
          java.version=${java.version}
          command.line.prop=${command.line.prop}

          posted @ 2006-03-28 14:46 jbob 閱讀(1489) | 評(píng)論 (0)編輯 收藏

          接上期

          1. ..
          2. ..
          3. ..
          4. ..
          5. 建立新的項(xiàng)目
            mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app
            首先,程序會(huì)從遠(yuǎn)程下載必要的jar包到你的localRepository,即我們剛剛設(shè)置的[d:/repo]
            然后,會(huì)在當(dāng)前目錄下面生成my-app文件夾,包括簡(jiǎn)單的包結(jié)構(gòu)[java,test]和一個(gè)HelloWorld程序及測(cè)試。
            以及pom.xml文件。
            注意:pom.xml contains the Project Object Model (POM) for this project.
            The POM is the basic unit of work in Maven。
          6. 編譯
            mvn compile
            第一次運(yùn)行會(huì)下載很多jar包。而且機(jī)器負(fù)荷會(huì)很重。
            運(yùn)行這個(gè)命令需要在pom.xml相同目錄下面
            這個(gè)編譯指揮編譯主程序,不會(huì)編譯test下面的程序。
            如果需要單獨(dú)編譯test,請(qǐng)運(yùn)行 mvn test-compile
            compile之后會(huì)生成target文件夾,主程序編譯在classes下面,測(cè)試程序放在test-classes下
          7. 測(cè)試
            mvn test. 會(huì)自動(dòng)先編譯在運(yùn)行測(cè)試
          8. 打包
            mvn package
            打包之前會(huì)進(jìn)行編譯,測(cè)試




          posted @ 2006-03-26 22:29 jbob 閱讀(779) | 評(píng)論 (0)編輯 收藏

          maven 是一個(gè)java項(xiàng)目管理工具,深化了ant,但又有自己一整套的項(xiàng)目集成策略。
          目前的版本是2.0.2

          1. 下載maven 2 [鏈接],解壓縮。
          2. 配置環(huán)境變量,maven_home, path
          3. cmd-> mvn --version 檢查是否安裝成功 [顯示版本號(hào),則說(shuō)明安裝成功]
          4. 配置
            Maven的配置分為三個(gè)層次


            Project - pom.xml,針對(duì)某個(gè)項(xiàng)目的配置
            Installation
            User -針對(duì)某個(gè)用戶(hù)的配置


            我們首先配置主要是user級(jí)別的,主要包括兩點(diǎn)
            設(shè)置本地的資源庫(kù)和代理服務(wù)器[如果需要的話]
            在%maven_home%/conf/setting.xml中配置:

            <localRepository>d:/repo</localRepository>?

            <proxy>
            ??
            <id>proxy1</id>
            ??
            <active>true</active>
            ??
            <protocol>http</protocol>
            ??
            <username></username>
            ??
            <password></password>
            ??
            <host>222.136.91.1</host>
            ??
            <port>80</port>
            ??
            <nonProxyHosts></nonProxyHosts>
            </proxy>


            修改之后copy一份到${home}/.m2 [最新版本不需要此步驟]



          Technorati :

          posted @ 2006-03-25 23:06 jbob 閱讀(1265) | 評(píng)論 (0)編輯 收藏
          僅列出標(biāo)題  

          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(3)

          隨筆分類(lèi)

          隨筆檔案

          生活感悟

          順手

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 鹤岗市| 乐都县| 红河县| 区。| 阿尔山市| 潮州市| 永济市| 廉江市| 德阳市| 沧源| 武功县| 赫章县| 利川市| 莱州市| 秦皇岛市| 山丹县| 岑巩县| 济阳县| 望江县| 阿瓦提县| 额敏县| 浮梁县| 凤翔县| 额尔古纳市| 乌审旗| 汉寿县| 千阳县| 凤城市| 秭归县| 萨嘎县| 资源县| 抚远县| 安西县| 贡山| 明溪县| 上犹县| 札达县| 德钦县| 思南县| 万载县| 田阳县|