Maven學習一:使用Myeclipse建立Maven項目

使用Myeclipse2014建立Maven項目有以下幾種方式:java

 

一、建立Maven Java項目web

 

  1.1 選擇新建Maven項目
apache

1.二、選擇建立簡單項目api

1.三、填寫項目信息架構

1.四、建立成功後項目目錄結構app

  1.五、建立後pom.xml文件內容eclipse

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" 
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4   <modelVersion>4.0.0</modelVersion>
 5   <groupId>com.luwei.test</groupId>
 6   <artifactId>java-maven</artifactId>
 7   <version>0.0.1-SNAPSHOT</version>
 8   <name>JavaMaven</name>
 9   <description>JavaMaven Test</description>
10   <build>
11     <plugins>
12       <plugin>
13         <artifactId>maven-compiler-plugin</artifactId>
14         <configuration>
15           <source>1.6</source>
16           <target>1.6</target>
17         </configuration>
18       </plugin>
19     </plugins>
20   </build>
21 </project>

 

2 建立Maven Web項目webapp

 

 2.一、選擇建立Maven項目jsp

2.2 不選擇建立簡單項目maven

2.三、選擇建立webapp項目

2.四、填寫項目信息

2.五、生成後的項目目錄結構

2.六、增長項目缺失目錄,同時修改項目相關問題

  經過Myeclipse建立的Web項目有時會出現項目目錄不對的問題,手動新增相關目錄便可,

 

2.七、添加項目基礎依賴

junit.jar/jsp-api.jar/jstl.jar/servlet-api.jar

2.七、建立後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>com.luwe.test</groupId>
 5     <artifactId>web</artifactId>
 6     <packaging>war</packaging>
 7     <version>0.0.1-SNAPSHOT</version>
 8     <name>web Maven Webapp</name>
 9     <url>http://maven.apache.org</url>
10     <build>
11         <finalName>web</finalName>
12         <plugins>
13             <!-- 編碼和編譯和JDK版本 -->
14             <plugin>
15                 <groupId>org.apache.maven.plugins</groupId>
16                 <artifactId>maven-compiler-plugin</artifactId>
17                 <version>3.6.0</version>
18                 <configuration>
19                     <source>1.7</source>
20                     <target>1.7</target>
21                     <encoding>UTF-8</encoding>
22                 </configuration>
23             </plugin>
24         </plugins>
25     </build>
26 
27     <dependencies>
28         <dependency>
29             <groupId>junit</groupId>
30             <artifactId>junit</artifactId>
31             <version>4.11</version>
32             <scope>test</scope>
33         </dependency>
34         <dependency>
35             <groupId>javax.servlet</groupId>
36             <artifactId>servlet-api</artifactId>
37             <version>3.0-alpha-1</version>
38         </dependency>
39         <dependency>
40             <groupId>javax.servlet.jsp</groupId>
41             <artifactId>jsp-api</artifactId>
42             <version>2.1</version>
43         </dependency>
44         <dependency>
45             <groupId>javax.servlet</groupId>
46             <artifactId>jstl</artifactId>
47             <version>1.2</version>
48         </dependency>
49     </dependencies>
50 </project>

 

三、建立JavaWeb項目同時增長Maven支持

  3.一、選擇建立JaveEE Web項目

 

3.二、一路Next到填寫Maven Project Support Setting

  

  選擇Myeclipse JEE project structure 會生成Myeclipse自身的項目架構,此時只須要將相關內容進行配置便可

  

  選擇Standard Maven project structure 會生成標準的Maven項目架構,建議選用此選項

四、建立項目件的Maven依賴

  在多組件項目,或者爲了代碼重用,一般會考慮將相同的代碼從具體項目中抽取出來造成基礎項目或者core項目全部其餘項目依賴於當前基本項目,Maven也能夠採用相同的方式,在Maven的項目依賴中,被依賴項目的package必須是pom類型,依賴項目只須要在pom.xml中添加<parent>節點便將父項目中的Maven配置導入到當前項目。
父項目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/xsd/maven-4.0.0.xsd">
 3     <modelVersion>4.0.0</modelVersion>
 4     <groupId>com.luwei.test</groupId>
 5     <artifactId>java</artifactId>
 6     <version>0.0.1</version>
 7     <build>
 8         <plugins>
 9             <plugin>
10                 <artifactId>maven-compiler-plugin</artifactId>
11                 <configuration>
12                     <source>1.7</source>
13                     <target>1.7</target>
14                 </configuration>
15             </plugin>
16         </plugins>
17     </build>
18     <dependencies>
19         <dependency>
20             <groupId>junit</groupId>
21             <artifactId>junit</artifactId>
22             <version>4.11</version>
23             <scope>test</scope>
24         </dependency>
25         <dependency>
26             <groupId>javax.servlet</groupId>
27             <artifactId>servlet-api</artifactId>
28             <version>3.0-alpha-1</version>
29         </dependency>
30         <dependency>
31             <groupId>javax.servlet.jsp</groupId>
32             <artifactId>jsp-api</artifactId>
33             <version>2.1</version>
34         </dependency>
35         <dependency>
36             <groupId>javax.servlet</groupId>
37             <artifactId>jstl</artifactId>
38             <version>1.2</version>
39         </dependency>
40     </dependencies>
41     <packaging>pom</packaging>
42 </project>

子項目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>com.luwe.test</groupId>
 5     <artifactId>web</artifactId>
 6     <packaging>war</packaging>
 7     <name>web Maven Webapp</name>
 8     <url>http://maven.apache.org</url>
 9     <build>
10         <finalName>web</finalName>
11     </build>
12     <parent>
13         <groupId>com.luwei.test</groupId>
14         <artifactId>java</artifactId>
15         <version>0.0.1</version>
16     </parent>
17 </project>
相關文章
相關標籤/搜索