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 閱讀(1698) 評論(1)  編輯  收藏

          評論

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

          nice@  回復  更多評論   


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


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 墨江| 塔城市| 蛟河市| 梁山县| 平和县| 黄石市| 香港 | 平阴县| 昭觉县| 凌海市| 白沙| 正镶白旗| 余干县| 玛曲县| 财经| 棋牌| 清水河县| 九龙县| 育儿| 三穗县| 开江县| 新津县| 博爱县| 盈江县| 郸城县| 邵阳市| 奈曼旗| 保定市| 兴仁县| 东港市| 永兴县| 元江| 滨海县| 南川市| 南和县| 罗田县| 阜康市| 临安市| 伊川县| 永登县| 临猗县|