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 閱讀(2625) | 評論 (6)編輯 收藏
               摘要:   閱讀全文
          posted @ 2006-04-19 22:03 jbob 閱讀(1572) | 評論 (5)編輯 收藏
          13 jar包依賴
          我們在mvn 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.

          舉例說明
          如果我們的project需要用到log4j包,那么我們可以先google--"site:www.ibiblio.org maven2 log4j".
          Index of /maven2/log4j/log4j? 下面有maven-metadata.xml 描述了groupId,artifactId,version等等。
          獲取了這些信息之后,你就可以在pom.xml中添加依賴了
          <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 閱讀(1499) | 評論 (4)編輯 收藏

          9 安裝[install]
          mvn install
          會將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都會編譯到j(luò)ar文件中
          而${basedir}/src/main/resources 下的內(nèi)容會直接位于jar文件的頂部
          測試用資源文件-> ${basedir}/src/test/resources
          引用時參照此例:
          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)樵瓉砟J(rèn)的filter為false所以要加上上面的代碼
          e.g
          我們在src/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還可以用其他的外部文件,不一定來自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 會得到類似的效果。

          當(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還可以來自系統(tǒng)設(shè)置以及可以自定義:
          # application.properties
          java.version=${java.version}
          command.line.prop=${command.line.prop}

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

          <2006年3月>
          2627281234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          生活感悟

          順手

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 九龙城区| 亚东县| 定日县| 邯郸县| 刚察县| 台南县| 谷城县| 汉川市| 阿克陶县| 喀喇| 临泉县| 始兴县| 恩施市| 恩平市| 威海市| 望城县| 溧水县| 晋州市| 桃园县| 拜泉县| 和田县| 孟村| 新丰县| 清苑县| 洛隆县| 太康县| 牙克石市| 曲靖市| 邢台市| 桑植县| 赞皇县| 定远县| 子洲县| 繁峙县| 玉山县| 稻城县| 富民县| 大邑县| 嘉义县| 南开区| 贡山|