posts - 6,  comments - 15,  trackbacks - 0
               摘要: 使用maven2 構(gòu)建 Webapp應用程序
          基于以下框架:spring,hibernate,webwork.2.2.2  閱讀全文
          posted @ 2006-04-21 10:09 jbob 閱讀(2618) | 評論 (6)編輯 收藏
               摘要:   閱讀全文
          posted @ 2006-04-19 22:03 jbob 閱讀(1569) | 評論 (5)編輯 收藏
          13 jar包依賴
          我們在mvn install后在local repo中生成的jar包也可以被其他項目所引用
          <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中間設置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中設置遠程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) | 評論 (4)編輯 收藏

          9 安裝[install]
          mvn install
          會將package之后的jar包copy到
          <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 >


          當然你需要設置server
          mvn site-deploy
          mvn clean
          mvn idea:idea [為IDE工具idea生成項目文件]

          11 Resource
          ${basedir}/src/main/resources都會編譯到jar文件中
          而${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 >


          因為原來默認的filter為false所以要加上上面的代碼
          e.g
          我們在src/main/resources下面建立application.properties文件
          ?# application.properties
          ?application.name=${pom.name}
          ?application.version=${pom.version}
          運行:mvn process-resources
          在target/classes下面,
          application.properties:
          ?# application.properties
          ?application.name=Maven Quick Start Archetype
          ?application.version=1.0-SNAPSHOT
          這就是所謂的filter.
          當然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}
          這樣在運行mvn process-resources 會得到類似的效果。

          當然我們也可以直接在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)設置以及可以自定義:
          # application.properties
          java.version=${java.version}
          command.line.prop=${command.line.prop}

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

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

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          生活感悟

          順手

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 罗田县| 鹰潭市| 冷水江市| 张家港市| 屏南县| 广昌县| 沂源县| 望江县| 娄底市| 浦江县| 灯塔市| 木里| 寻乌县| 大余县| 平阳县| 新乐市| 宜君县| 綦江县| 玉环县| 太谷县| 桐柏县| 九龙城区| 石狮市| 崇左市| 绥阳县| 阿勒泰市| 大庆市| 四川省| 岗巴县| 运城市| 柏乡县| 襄汾县| 通州区| 祁连县| 轮台县| 定州市| 贵州省| 通许县| 湾仔区| 普格县| 通州市|