日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Maven下,spring+struts2+ibatis整合

 昵稱(chēng)16968929 2014-04-24
一、Maven的安裝配置
參考此博客:http://qincao./blog/614022
PS:很簡(jiǎn)潔易懂,引用一下,呵呵

二、使用maven構(gòu)建多工程
1、通過(guò)cmd,進(jìn)入Dos下執(zhí)行mvn創(chuàng)建指令
2、創(chuàng)建主工程,假設(shè)在E盤(pán)創(chuàng)建
Java代碼  收藏代碼
  1. mvn archetype:create -DgroupId=com.cy -DartifactId=mallshop -Dversion=1.0  

備注:
  • <groupId>:一個(gè)項(xiàng)目群的ID,一個(gè)項(xiàng)目群可以包含多個(gè)項(xiàng)目
  • <artifactId>:一個(gè)項(xiàng)目的ID,是每個(gè)項(xiàng)目的唯一ID.
  • <version>:描述了項(xiàng)目當(dāng)前的版本.
需要注意,必須修改pom.xml,參考錯(cuò)誤一的解決方法

3、進(jìn)入主工程下(Dos下執(zhí)行cd E:\mallshop進(jìn)入),創(chuàng)建多個(gè)子工程,如下:
Java代碼  收藏代碼
  1. mvn archetype:create -DgroupId=com.cy.biz.dal -DartifactId=mallshop-biz-dal -Dversion=1.0  
  2. mvn archetype:create -DgroupId=com.cy.biz.core -DartifactId=mallshop-biz-core -Dversion=1.0  
  3. mvn archetype:create -DgroupId=com.cy.biz.manager -DartifactId=mallshop-biz-manager -Dversion=1.0  
  4. mvn archetype:create -DgroupId=com.cy.web -DartifactId=mallshop-web -Dversion=1.0 -DarchetypeArtifactId=maven-archetype-webapp  

 
引用
其中修改的重點(diǎn)為打包方式(war/jar)改為pom形式,這也就意味這這是一個(gè)父工程,另外版本號(hào)默認(rèn)是SNAPSHOT意思是快照的意思,就是項(xiàng)目開(kāi)發(fā)中的意思,你要是看著不爽可以把它刪掉,另外需要說(shuō)明一下dependencyManagement標(biāo)簽,這個(gè)標(biāo)簽表示子類(lèi)可以隱式的繼承父pom文件的依賴(lài)庫(kù),在子pom中不需要指定版本號(hào),推薦這樣,這樣可以方便開(kāi)發(fā),你要修改什么依賴(lài)的版本只需要更改父pom就可以了,dependencies是顯示繼承,你要是在子pom中聲明,就必須寫(xiě)明版本號(hào),不寫(xiě)默認(rèn)就繼承了。


4、修改各個(gè)pom,添加相關(guān)依賴(lài)
Java代碼  收藏代碼
  1.    
  2.  <dependency>  
  3. <groupId>com.cy.biz.dal</groupId>  
  4. <artifactId>cy-biz-dal</artifactId>  
  5. <version>${project.version}</version>  
  6.  </dependency>  


5、將Maven項(xiàng)目轉(zhuǎn)為Eclipse項(xiàng)目
具體操作為將dos命令窗口切換到Maven項(xiàng)目的目錄下,輸入命令:
mvn eclipse:eclipse

6、導(dǎo)入eclipse
  • 在該項(xiàng)目上點(diǎn)右鍵Maven->Enable
  • 在該項(xiàng)目上點(diǎn)右鍵Build Path->Configure Build Path->Java Build Path->Libraries->去掉Maven添加的變量路徑
  • 在該項(xiàng)目上點(diǎn)右鍵MyEclipse->Add Web Capabilities->修改Web root地址(點(diǎn)【瀏覽】按鈕指定為當(dāng)前工作空間下的src/main/webapp文件夾)
  • 配置完畢,可以用MyEclipse插件配置服務(wù)器等開(kāi)始正常開(kāi)發(fā),自動(dòng)部署,調(diào)試等操作了。


三、整合ssi
1、在主工程下的pom.xml中添加相應(yīng)的配置,完整如下
Java代碼  收藏代碼
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns="http://maven./POM/4.0.0" xmlns:xsi="http://www./2001/XMLSchema-instance" xsi:schemaLocation="http://maven./POM/4.0.0 http://maven./maven-v4_0_0.xsd">  
  3.   <modelVersion>4.0.0</modelVersion>  
  4.   <groupId>com.cy</groupId>  
  5.   <artifactId>mallshop</artifactId>  
  6.   <packaging>pom</packaging>  
  7.   <version>1.0</version>  
  8.   <name>mallshop</name>  
  9.   <url>http://maven.</url>  
  10.  <dependencies>  
  11.    <dependency>  
  12.             <groupId>junit</groupId>  
  13.             <artifactId>junit</artifactId>  
  14.             <version>4.7</version>  
  15.             <scope>test</scope>  
  16.         </dependency>  
  17.              <dependency>  
  18.             <groupId>log4j</groupId>  
  19.             <artifactId>log4j</artifactId>  
  20.             <version>1.2.14</version>  
  21.         </dependency>  
  22.         <dependency>  
  23.             <groupId>commons-dbcp</groupId>  
  24.             <artifactId>commons-dbcp</artifactId>  
  25.             <version>1.2.2</version>  
  26.         </dependency>  
  27.         <dependency>  
  28.             <groupId>commons-beanutils</groupId>  
  29.             <artifactId>commons-beanutils</artifactId>  
  30.             <version>1.7.0</version>  
  31.         </dependency>  
  32.         <dependency>  
  33.             <groupId>org.springframework</groupId>  
  34.             <artifactId>spring-mock</artifactId>  
  35.             <version>2.0.8</version>  
  36.         </dependency>  
  37.         <dependency>  
  38.             <groupId>org.springframework</groupId>  
  39.             <artifactId>spring-webmvc</artifactId>  
  40.             <version>2.5.6</version>  
  41.         </dependency>  
  42.         <dependency>  
  43.             <groupId>mysql</groupId>  
  44.             <artifactId>mysql-connector-java</artifactId>  
  45.             <version>5.1.9</version>  
  46.         </dependency>  
  47.         <dependency>  
  48.             <groupId>org.springframework</groupId>  
  49.             <artifactId>spring</artifactId>  
  50.             <version>2.5.6</version>  
  51.         </dependency>  
  52.             <dependency>  
  53.             <groupId>org.apache.ibatis</groupId>  
  54.             <artifactId>ibatis-sqlmap</artifactId>  
  55.             <version>2.3.4.726</version>  
  56.         </dependency>  
  57.         <dependency>  
  58.             <groupId>javax.servlet</groupId>  
  59.             <artifactId>servlet-api</artifactId>  
  60.             <version>2.4</version>  
  61.         </dependency>  
  62.         <dependency>  
  63.             <groupId>javax.mail</groupId>  
  64.             <artifactId>mail</artifactId>  
  65.             <version>1.4.1</version>  
  66.         </dependency>  
  67.         <dependency>  
  68.       <groupId>org.apache.struts</groupId>  
  69.       <artifactId>struts2-jfreechart-plugin</artifactId>  
  70.     <version>2.1.8</version>  
  71.     </dependency>  
  72.   </dependencies>  
  73.   <build>  
  74.         <plugins>  
  75.             <plugin>  
  76.                 <groupId>org.apache.maven.plugins</groupId>  
  77.                 <artifactId>maven-compiler-plugin</artifactId>  
  78.                 <configuration>  
  79.                     <source>1.6</source>  
  80.                     <target>1.6</target>   
  81.                     <encoding>GBK</encoding>  
  82.                 </configuration>  
  83.             </plugin>  
  84.         </plugins>  
  85.     </build>  
  86.   <modules>  
  87.     <module>mallshop-biz-dal</module>  
  88.     <module>mallshop-biz-core</module>  
  89.     <module>mallshop-biz-manager</module>  
  90.     <module>mallshop-web</module>  
  91.   </modules>  
  92. </project>    

PS:具體根據(jù)自己的需要

2、執(zhí)行如下mvn指令,完成
  mvn install
  mvn clean
  mvn eclipse:eclipse
  mvn clean package -Dmaven.test.skip=true;
  執(zhí)行下載
  mvn eclipse:clean eclipse:eclipse -DdownloadSources=true

3、Bingo!整合完畢!!

在此過(guò)程中遇到錯(cuò)誤整理:


1、未執(zhí)行如下操作,就創(chuàng)建子工程,會(huì)報(bào)這樣的錯(cuò)誤:

引用
Embedded error: Unable to add module to the current project as it is not of packaging type 'pom'

解決方案:
修改主工程目錄下的pom文件,設(shè)置如下:
<packaging>pom</packaging>

2、source 1.3 中不支持泛型
maven打包時(shí)始終出現(xiàn)以下提示:

引用
1、-source 1.3 中不支持泛型(請(qǐng)使用 -source 5 或更高版本以啟用泛型)List<User> userList= new ArrayList<User>();

2、-source 1.3 中不支持注釋?zhuān)ㄕ?qǐng)使用 -source 5 或更高版本以啟用注釋?zhuān)〡WebService(endpointInterface = "com.webservice.service.LoadService")


解決辦法:
用命令mvn -v查看結(jié)果:
引用
C:\Users\Administrator>mvn -v
Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800)
Java version: 1.6.0
Java home: D:\Program Files\Java\jdk1.6.0\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows vista" version: "6.1" arch: "x86" Family: "windows"

PS:顯然與所配置的JDK無(wú)關(guān)。

最終解決辦法:

在項(xiàng)目的pom.xml(放在主工程下的)中,添加   
Java代碼  收藏代碼
  1. <build>  
  2.     <plugins>  
  3.       <plugin>  
  4.         <groupId>org.apache.maven.plugins</groupId>  
  5.         <artifactId>maven-compiler-plugin</artifactId>  
  6.         <configuration>  
  7.           <source>1.5</source>  
  8.           <target>1.5</target>  
  9.         </configuration>  
  10.       </plugin>  
  11.     </plugins>  
  12. </build>   


再執(zhí)行mvn install,OK。

3、新建的類(lèi)中,右擊,執(zhí)行相應(yīng)操作,會(huì)出現(xiàn)如下提示框:


原因是找不到路徑,具體的操作方式如下:
在web工程中新建Source Folder,取名為src/main/resources或src/main/java,然后新建package,在此包下創(chuàng)建class;在src->main中新建Folder,取名為webconfig,存放spring配置文件  

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多