小菜毛毛技術分享

          與大家共同成長

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            164 Posts :: 141 Stories :: 94 Comments :: 0 Trackbacks

                  迷迷糊糊的接觸java也有大半年之久了,期間一直用java來開發web項目,從最開始的helloworld,到jdbc鏈接數據庫,到現在的用struts、hibernate、spring完成一個項目,收獲頗多。

                  所以從今天開始寫一個系列詳細的講述如何用maven,struts2、hibernate3、spring2、Tiles2以及mysql完成一個web project。對自己做一個總結,也希望能幫助有需要的人。僅此而已。
                  項目構建工具:maven
                  IDE:myeclipse6.5
                  數據庫:mysql5
                  框架:SSH
                  其他涉及:powerdesigner12、Tiles2、fckeditor、jdk1.6

                  SSH筆記目錄

                  SSH筆記一  用maven構建項目(源碼下載ssim1.rar)
                  SSH筆記二  整合hibernate和spring(源碼下載ssim2.rar
                  SSH筆記三  反向生成DAO  優化開發目錄
                  SSH筆記四  整合struts2
                  SSH筆記五  整合Tiles2
                  SSH筆記六  完成登錄驗證

                  今天的任務就是完成一個maven構建的標準開發目錄,在myeclipse6.5中,右鍵— Run As—Maven install一下,效果圖如下:

                             

                  1.    maven2的安裝(略)
                  2.    用maven創建myeclipse下的標準web項目
                  2.1    在命令行下,用maven創建一個web project
          1mvn archetype:create  -DgroupId=net.selitech.ssim  -DartifactId=ssim  -DarchetypeArtifactId=maven-archetype-webapp

                  2.2    補全某些目錄(命令行下切換到項目)

          1cd ssh\src
          2mkdir main\java
          3mkdir test\resources
          4mkdir test\java

                  2.3    打開項目,修改該pom.xml如下 

           1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
           3   <modelVersion>4.0.0</modelVersion>
           4   <groupId>net.selitech.ssim</groupId>   <!--工程的組織或團隊的唯一標識,并且這個也是一個項目的關鍵標識,推薦使用這個組織或團隊的完整域名-->
           5   <artifactId>ssim</artifactId>                <!--工程的基本名稱 -->
           6   <packaging>war</packaging>              <!--打包的類型,可以為war、jar、ear等等-->
           7   <version>1.0-SNAPSHOT</version>     <!--項目版本號-->
           8   <name>SSIM Maven Webapp</name>  <!--工程顯示的名稱-->
           9   <description> Web application</description>  <!--對工程的基本描述-->
          10 
          11   <build><!--主要用于編譯設置-->
          12     <finalName>${artifactId}</finalName>
          13     <plugins>
          14       <plugin>
          15         <groupId>org.apache.maven.plugins</groupId>
          16         <artifactId>maven-compiler-plugin</artifactId>
          17         <configuration>
          18           <source>1.6</source>
          19           <target>1.6</target>
          20           <encoding>UTF8</encoding>
          21         </configuration>
          22       </plugin>
          23       <plugin>
          24         <groupId>org.apache.maven.plugins</groupId>
          25         <artifactId>maven-surefire-plugin</artifactId>
          26         <version>2.4.2</version>
          27         <configuration>
          28           <skipTests>true</skipTests>
          29         </configuration>
          30       </plugin>
          31       <plugin>
          32         <artifactId>maven-war-plugin</artifactId>
          33         <configuration>
          34           <webappDirectory>${basedir}/src/main/webapp</webappDirectory>
          35           <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
          36         </configuration>
          37       </plugin>
          38     </plugins>
          39   </build>
          40   <!--定義依賴(項目中需要依賴的包-->
          41   <dependencies>
          42     <dependency>
          43       <groupId>junit</groupId>
          44       <artifactId>junit</artifactId>
          45       <version>4.5</version>
          46       <scope>test</scope>
          47     </dependency>
          48   </dependencies>
          49 </project>

                  2.4    在命令行下回到項目ssim目錄下,運行

          1mvn eclipse:eclipse

                  2.5    在myeclipse中導入生成的ssim項目,修改.mymetadata文件為

           1<?xml version="1.0" encoding="UTF-8"?>
           2<project-module
           3  type="WEB"
           4  name="ssim"
           5  id="myeclipse.1234059775961"
           6  context-root="/ssim"
           7  j2ee-spec="1.4"
           8  archive="ssim.war">
           9  <attributes>
          10    <attribute name="webrootdir" value="src/main/webapp" />
          11  </attributes>
          12</project-module>

                  2.6修改.project文件為        

           1 <?xml version="1.0" encoding="UTF-8"?>
           2 <projectDescription>
           3     <name>ssim</name>
           4     <comment>Web application</comment>
           5     <projects>
           6     </projects>
           7     <buildSpec>
           8         <buildCommand>
           9             <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
          10             <arguments>
          11             </arguments>
          12         </buildCommand>
          13         <buildCommand>
          14             <name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
          15             <arguments>
          16             </arguments>
          17         </buildCommand>
          18         <buildCommand>
          19             <name>org.eclipse.jdt.core.javabuilder</name>
          20             <arguments>
          21             </arguments>
          22         </buildCommand>
          23         <buildCommand>
          24             <name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
          25             <arguments>
          26             </arguments>
          27         </buildCommand>
          28         <buildCommand>
          29             <name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
          30             <arguments>
          31             </arguments>
          32         </buildCommand>
          33         <buildCommand>
          34             <name>org.eclipse.wst.validation.validationbuilder</name>
          35             <arguments>
          36             </arguments>
          37         </buildCommand>
          38     </buildSpec>
          39     <natures>
          40         <nature>org.maven.ide.eclipse.maven2Nature</nature>
          41         <nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
          42         <nature>org.eclipse.jdt.core.javanature</nature>
          43         <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
          44     </natures>
          45 </projectDescription>
          46 

                  好了,用maven2構建的一個標準開發目錄就建好了,將項目導入myeclipse,開發、調試、發布一舉多得。今天到此為止,明天繼續

                  下一次:SSH筆記二  整合hibernate和spring

          posted on 2009-08-11 12:29 小菜毛毛 閱讀(5887) 評論(0)  編輯  收藏 所屬分類: J2EE相關技術與框架
          主站蜘蛛池模板: 乌拉特前旗| 盐边县| 广南县| 西充县| 凤庆县| 蚌埠市| 峨边| 石渠县| 昌黎县| 兴宁市| 库尔勒市| 蚌埠市| 新安县| 九寨沟县| 收藏| 中卫市| 合作市| 敦煌市| 铜梁县| 汤阴县| 当涂县| 道真| 江津市| 金寨县| 台北县| 成都市| 杭锦旗| 什邡市| 吴桥县| 溆浦县| 无锡市| 米林县| 平定县| 廉江市| 商都县| 张家港市| 合江县| 岑巩县| 北川| 富蕴县| 高尔夫|