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

          評論

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

          nice@  回復  更多評論   


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


          網站導航:
           

          導航

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

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 无为县| 桦川县| 阳西县| 华坪县| 织金县| 普陀区| 武山县| 隆安县| 突泉县| 舟山市| 渑池县| 青川县| 咸阳市| 芮城县| 陵川县| 石河子市| 麦盖提县| 乐亭县| 花莲县| 和静县| 焉耆| 正宁县| 商洛市| 白水县| 莱阳市| 阿拉善盟| 乳源| 罗山县| 东丽区| 湘潭市| 和硕县| 夏津县| 蚌埠市| 桂阳县| 武邑县| 瑞安市| 平湖市| 漳州市| 镇赉县| 遵化市| 西青区|