一、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)建
- 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è)子工程,如下:
- mvn archetype:create -DgroupId=com.cy.biz.dal -DartifactId=mallshop-biz-dal -Dversion=1.0
- mvn archetype:create -DgroupId=com.cy.biz.core -DartifactId=mallshop-biz-core -Dversion=1.0
- mvn archetype:create -DgroupId=com.cy.biz.manager -DartifactId=mallshop-biz-manager -Dversion=1.0
- 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)
-
- <dependency>
- <groupId>com.cy.biz.dal</groupId>
- <artifactId>cy-biz-dal</artifactId>
- <version>${project.version}</version>
- </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)的配置,完整如下
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.cy</groupId>
- <artifactId>mallshop</artifactId>
- <packaging>pom</packaging>
- <version>1.0</version>
- <name>mallshop</name>
- <url>http://maven.</url>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.7</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.14</version>
- </dependency>
- <dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
- <version>1.2.2</version>
- </dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>1.7.0</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-mock</artifactId>
- <version>2.0.8</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- <version>2.5.6</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.9</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring</artifactId>
- <version>2.5.6</version>
- </dependency>
- <dependency>
- <groupId>org.apache.ibatis</groupId>
- <artifactId>ibatis-sqlmap</artifactId>
- <version>2.3.4.726</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
- </dependency>
- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <version>1.4.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.struts</groupId>
- <artifactId>struts2-jfreechart-plugin</artifactId>
- <version>2.1.8</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>GBK</encoding>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <modules>
- <module>mallshop-biz-dal</module>
- <module>mallshop-biz-core</module>
- <module>mallshop-biz-manager</module>
- <module>mallshop-web</module>
- </modules>
- </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(放在主工程下的)中,添加
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- </plugins>
- </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配置文件
|