First, install the M2eclipse plug-in
To build a Maven project with Eclipse, we need to install the Meeclipse plug-in first, and now the newer version of Eclipse has its own plugin, which can be viewed or installed in a few ways.
Click the Eclipse menu bar Help->eclipse Marketplace to search for the plugin maven integration for Eclipse and click Install, such as:
Ii. Building a MAVEN project
1.1 Select Maven--------New in the new window. Click Next.
1.2 Select the project path: Use default Workspace the location defaults workspace.
1.3 Select project Type
Select Maven-archetype-webapp in the Artifact ID
1.4 Enter the group ID and Artifact ID, and the package
Group IDs generally write large project names. The Artifact ID is the subproject name (the name of the project that was created).
For example, the Spring Web package, Group id:org.springframework,artifactid:spring-web.
Package is the default for you to build a bag, do not write or can.
1.5 Just set up the file structure as well.
1.6 Fix the project error: Add Apache Tomcat package to the Server Runtime, Bulid Path, add Libraries, on the project to solve the JSP error problem.
2. Configuring MAVEN Projects
The next step is to change a lot of configurations.
2.1 Show hidden source folder
Next you need to show Src/main/java,src/test/java, src/test/resources three folders. Right-click the project root Bulid path, Configure Bulid path to modify JRE to version 1.6
The modified project directory is as follows, and the project name has an error
Next, fix the error tag at the project name:
Under Eclipse's working directory, find Org.eclipse.wst.common.project.facet.core.xml under \yjtx\.settings\
The problem can be resolved by updating the <installed facet= "java" version= "1.5"/> to the same version as the JRE and after the 1.6 F5 refresh project in the office.
2.2 Viewing the class path
Right-click Project, Java Build Path, Source
There should be 4 folders below. Src/main/java,src/main/resources,src/test/java, Src/test/resources.
Double-click the output folder for each of the folders to select the path.
Src/main/java,src/main/resources, choose target/classes;
Src/test/java, src/test/resources, choose target/test-classes;
Select the Allow output folders for source folders.
Here you can also change the order in which folders are displayed: Click Order and Export.
2.3 Setting up Deployment Assemblies (Web Deployment Assembly)
Right-click the project root directory by clicking Bulid Path, Configure Bulid path, Deployment Assembly.
When setting up a formal deployment: Delete the test directory, src other directories point to Web-inf/classes,maven Dependencies point to Web-inf/lib directory
Iii. adding a jar package to a MAVEN project
Open the Pom.xml in the project.
① If you know the group ID and Artifact ID of the jar you want to add, you can choose to add it by clicking the Add button under Pom.xml's Dependencies tab.
②, open Pom.xml and go to the Pom.xml tab and manually write <dependency> node to add the jar under <dependencies>.
The dependency of the jar file can be found in the Maven jar repository and then manually added to the pom.xml.
When added into a jar package, there are some properties that need to be set, and most importantly, scope, which has the following values:
1. Compile, the default value, applies to all stages and is published along with the project.
2. Provided, similar to compile, expects that the JDK, container or user will provide this dependency. such as Servlet.jar.
3. Runtime, used only at runtime, such as JDBC driver, for run and test phases.
4. Test, used only during testing, to compile and run the test code. Will not be published with the project.
5. System, similar to provided, needs to explicitly provide an jar,maven that contains dependencies and does not look for it in repository.
Resources
Create a Maven project with eclipse