Figure and text explain the steps of creating a new Maven webapp project in MyEclipse (very detailed)

The process of creating a new Maven project (webapp directory structure) in MyEclipse is as follows:
 
1. New -> Project... -> Maven Project
 
2. Next, 
 
3. Next, select "maven-archetype-webapp" to create a project with a webapp directory structure

4. Fill in Group Id, Artifact Id, and Package (please refer to "Keywords" below), and click "Finish"

5. Take a break and wait for MyEclipse to create the project
After the creation is complete, the file directory structure is as follows:
 
6. (If you don't like the current file name) Modify the project name and storage path : right-click on the project -> refactor -> rename

7. Add the code directory:
Note: If it is MyEclipse2015, you only need to change the JRE System Library to "Workspace default JRE" in Java Build Path -> Libraries to automatically have those directories without the following operations.
Right-click on the project -> Build Path -> New Source Folder..., fill in "src/main/java"
(Note: MyEclipse2015 does not have this menu, just do this: right-click the project -> New -> Folder -> Folder Name, enter "src/main/java", and then repeat the steps to enter "src/test/java")
 
 
After adding, the test directory also automatically has:
 
8. (If necessary) modify the jdk used by the project: right-click the project -> Build Path -> Configure Build Path...
 
 
The final project directory structure is as follows:

9. Add the corresponding plugin , such as maven-compiler-plugin
[html] view plain copy
 
print ?
  1. <plugin>  
  2.  <groupId>org.apache.maven.plugins</groupId>  
  3.  <artifactId>maven-compiler-plugin</artifactId>  
  4.  <version>2.3.2</version>  
  5.  <configuration>  
  6.   <source>1.7</source>  
  7.   <target>1.7</target>  
  8.  </configuration>  
  9. </plugin>  
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
     <source>1.7</source>
     <target>1.7</target>
    </configuration>
   </plugin>

Key words:
GroupId: usually company name or organization name
ArtifactId: usually the project name
Packaging:打包类型,jar/war/rar/ear/pom等,默认是jar
Version:版本号,GroupId+ArtifactId+Packaging+Version构成项目的唯一标识
Snapshot:标识一个正在开发阶段、会经常更新、但尚未发布的版本
 
<dependency management>和<dependencies>的区别:
在父POM中用<dependency management>定义好version, scope, 和exclusions后,可以被子POM中用<dependencies>定义的依赖所继承使用。这样,如果有多个子POM的话,可以确保用同一套version, scope, 和exclusions。
 
Dependency Scope:
  • compile: 默认的scope。编译、测试、打包全都需要。compile参与依赖传递,就是说,项目A依赖于B(依赖scope是compile),项目C依赖于你的项目A,那么C也就依赖于B。
  • provided: 表示JDK或者容器会在Runtime时提供这些(jar),如servlet api,部署时是不需要它的,因为应用服务器肯定有这些东西。provided的东西在编译和测试时会用到,不参与传递依赖。
  • runtime: 表示编译时不需要,但测试和运行时需要,最终打包时会包含进去。
  • test: 只用于测试阶段(测试的编译和测试的运行),典型的就是junit的jar。
  • system: 和provided类似,但要求jar是系统里已有的,不会在repository里找,如rt.jar,tools.jar这些。
  • import: 简单的说,项目的pom可以继承另一个项目的pom,从而继承了父项目的依赖关系,但是因为之后single inheritance的限制,所以创造了import,使得你可以“导入”或者说“继承”任何一到多个项目的依赖关系。

找包的方法:
  1. 在GOOGLE里输入: maven spring repository 
  2. 得到:
[html] view plain copy
 
print ?
  1. <dependency>    
  2.     <groupId>org.springframework</groupId>  
  3.     <artifactId>spring</artifactId>  
  4.     <version>2.5.5</version>  
  5. </dependency>   
<dependency>  
    <groupId>org.springframework</groupId>
    <artifactId>spring</artifactId>
    <version>2.5.5</version>
</dependency> 

等Maven下载完jar包后,
  1. Stop server
  2. Redeploy/Reload application
  3. Start serve
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326227718&siteId=291194637