Digging in Java

          maven, spring, hibernate, et al

          Maven 淺談(二)-建一個spring webapp吧

          概述是挺沒意思的,還是寫代碼做項目有趣。那么來建一個webapp吧
          Maven命令是這樣的:
          mvn archetype:create -DgroupId=com.sky.birds -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
          它會在當前目錄下建一個my-webapp目錄。目錄下有pom.xml和src
          在src/main目錄下手工建一個java目錄,這里可以放java代碼,不明白為什么maven沒有自動把它建起來

          運行 mvn eclipse:eclipse,然后把項目導入eclipse里。在eclipse里打開pom.xml,這是maven的配置文件。如果裝了maven插件,可以看到pom.xml的編輯器里有Overview, Dependencies, Plugins等tab頁。
          maven的eclipse plugin可以在 http://m2eclipse.sonatype.org/installing-m2eclipse.html 找到

          既然要用到spring web MVC,那當然要有spring的web mvc jar,而web mvc又需要spring web,它們還要用到spring core, context,和beans, 這叫作dependency。而這些spring的庫之外,還需要commons-loggin等等。沒有maven的時候,就不得不搜索,下載,導入.....才能讓程序編譯。而在maven里,maven會管理這些dependencies。比如說,目前需要spring webmvc,那么就只需要把spring webmvc加到pom.xml的dependencies里
            <dependencies>
              
          <dependency>
                  
          <groupId>org.springframework</groupId>
                  
          <artifactId>spring-webmvc</artifactId>
                  
          <version>3.0.5.RELEASE</version>
                  
          <type>jar</type>
                  
          <scope>compile</scope>
              
          </dependency>

              .

            
          </dependencies>
          運行一下mvn eclipse:clean eclipse:eclipse,然后刷新eclipse,可以看到所需要的庫文件已經下載并且加在eclipse的classpath里了

          maven會在當前用戶的home目錄下建一個 .m2/repository 目錄,然后把下載下來的jar文件放在里面。windows下home目錄是在Document and Setting,而linux就在用戶自己的home目錄

          repository下的目錄結構是這樣的:
          /<groupId>/<artifactId>/<version>/
          比如說,在maven里配置了hibernate 3.2.7.ga,那么在repository下就是
          org/hibernate/hibernate/3.2.7.ga
          jar文件就放在這個目錄下


          posted on 2011-04-07 08:43 GX 閱讀(1699) 評論(1)  編輯  收藏

          評論

          # re: Maven 淺談(二)-建一個spring webapp吧[未登錄] 2011-10-26 11:01 matthew

          nice@  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2011年10月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 盐源县| 全南县| 永善县| 广平县| 香格里拉县| 高陵县| 那坡县| 岚皋县| 通化县| 瓦房店市| 莱州市| 忻城县| 区。| 阆中市| 台中县| 玛沁县| 旺苍县| 濮阳县| 高阳县| 商南县| 武穴市| 社旗县| 赞皇县| 蒲城县| 金门县| 顺义区| 东兰县| 抚顺县| 剑河县| 吴江市| 电白县| 永年县| 新乡市| 沐川县| 三原县| 托里县| 成安县| 清水河县| 读书| 鹿泉市| 石景山区|