Eclipse Configuring and using Maven

Source: Internet
Author: User

One, ecplise configuration maven 1, download Eclipse's maven plugin. (Some versions of Eclipse have already integrated this MAVEN plugin, so you don't have to download it.)

Need to download the M2eclipse plugin.

2, install M2eclipse plug-in.

Mode one: Use the first way to install, help--install New software Pop-up window and click the Add button to enter

HTTP Address: Http://m2eclipse.sonatype.org/sites/m2e,name:m2eclipse

Tick the option and wait for it to download and install, and then restart Eclipse when you're done.

      

Way two:

(1), download the above plugin.

(2). In the root directory of your eclipse installation

Create two folders under: Links,plugins (name can be taken casually), my two folders are located in: Path=d:/development/eclipse-javaee/eclipse (as a reference, use below)

(3). M2eclipse.rar unzip to the plugins directory

(4). Create a Maven.link in the links directory (the name can be arbitrarily taken, but it must be a file at the end of the. Link) file

Open and enter: Path= D:/development/eclipse-javaee/eclipse/plugins/maven (Please refer to your maven plugin above)

(5). Reboot Eclipse,ok, Finish, start after you open window---> Preferences will find one more option maven, stating that the installation was successful.

      

3. Configure Maven

Open Window---> Preferences, select Maven--->user Settings on the left, and fill in the Conf address of Setting.xml in our Maven directory in User Settings.

      

4. Whether the detection configuration is successful

Open Eclipse's window--->show View--->other. Then select Maven--->maven repositories open the Maven repository, and on the right there will be a local Repositories warehouse, and in this warehouse we can see the warehouses we used to configure in Setting.xml, which indicates the MAVEN configuration was successful. (If you click Local repository The following directory does not appear, you can right-click Local Repository Select rebuilt index, wait a while to generate an index back).

      

Second, create a MAVEN project within Eclipse. 1. Create a project

Under File--->new--->other, select Maven, and then select Maven Project.

    

2. Fill in the project information

It is recommended that you check this in this step so that the creation process will be simple.

    

If you fill in

    

Group Id: organization name, developer company or organization or individual name.

Artifact Id: Project name.

Version: Release information (SNAPSHOT beta, release release).

Packaging: Project type (War-->web project, Jar--->java project, POM---> Parent project).

Then click Finish to create a Web project. Its structure such as

    

3. Create Project Problems

(1) The Web project created automatically does not have an. xml file.

You can create the Web-inf folder yourself under the src--->main--->webapp directory, and then create the Web. XML below.

(2) The JRE version of the automatically created project defaults to 1.5, we need to change it to the version we need, and add the following code to the project's Pom.xml to set the version to 1.7.

    

<build>      <plugins>          <plugin>              <groupid>org.apache.maven.plugins</groupid >              <artifactId>maven-compiler-plugin</artifactId>              <version>3.5</version>              <!--Configuring detailed information--              <configuration>                  <source>1.7</source>                  <target>1.7 </target>                  <encoding>utf-8</encoding>              </configuration>            </plugin>      </plugins>  </build>

Configuration must be updated before the configuration can be used

      

4. Write the project

A servlet class is written under the src--->main--->java directory, and the class is created with an error.

    

We know that this is due to the lack of the corresponding Servlet-api.jar package, but we do not need to import this package, just need to configure the jar package coordinates in our Pom.xml file.

To configure the jar package coordinate code:

Right-click in the Pom.xml file and select Maven-->add dependency.

      

Enter SERVLET-API in the search box, search, and then select the appropriate version for the description after scope.

      

Modifying the code of a servlet

    

public class Blankservlet extends httpservlet{    private static final long serialversionuid = 1L;    @Override    protected void doget (HttpServletRequest request, httpservletresponse response)            throws Servletexception, IOException {        response.getwriter (). Write ("Hello Maven");    @Override    protected void DoPost (HttpServletRequest request, httpservletresponse response)            throws Servletexception, IOException {        this.doget (request, response);    }    }

Configure the Web. xml file

    

<servlet>     <display-name>BlankServlet</display-name>    <servlet-name>blankservlet </servlet-name>    <servlet-class>com.jack.servlet.BlankServlet</servlet-class>  </ servlet> <servlet-mapping>     <servlet-name>BlankServlet</servlet-name>     < Url-pattern>/blankservlet</url-pattern> </servlet-mapping>
5. Running the project

Run the project to run as a MAVEN project.

  

Enter command Tomcat:run to run the project

The project then runs successfully and gives the access address.

    

We then visited the servlet we wrote to test whether it was successful.

Eclipse Configuring and using Maven

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.