Maven project of SSH Framework

Keywords: Maven mvc

1, Maven learning objectives:

        1. Experience the convenience brought by Kaiyuan's excellent framework

        2. Knowledge verification of and custom MVC framework

        3. Mode transformation of development mode

2, Maven definition:

        1. Definition: Maven is a tool dedicated to building and managing java related projects.

                        The concept may be a little abstract. Next, use specific examples to help you understand. When doing the online bookstore project, we need to import many jar packages. Among them, the disadvantages are as follows:

                        1. jar packages need to be found one by one, which is very troublesome

                        2. There is a conflict between jar packages, which will lead to an error

                        So the Maven project came into being at this time.

3, How Maven works:

        I will use a picture to explain Maven's working principle:

 

  I will explain the principle in four steps: (the red font below is the noun to understand)

                1. If the project wants to use the jar package, first go to the maven local warehouse (find the jar package through the coordinates of pom: project object model and project object model) to find the target jar package, which will be automatically imported into the project and used

                2. If there is no target jar package in the local warehouse, the target jar package will be found in the Alibaba private server warehouse. If it is found, it will be automatically downloaded to the local warehouse and imported into the project for use

                3. If there is no target jar package in the Alibaba cloud warehouse (server), it will be downloaded from the foreign maven central warehouse and finally to the local warehouse
Note: if an error is reported after downloading from a foreign mave central warehouse, it is a code problem

4, How do I use Maven

          Steps:

                  1. Unzip folder

Put the compressed folder on a disk and decompress it (Note: the name of the folder should be in English, followed by the -- bin folder, as long as the innermost maven folder)

 

After decompression, don't use the two folders with -- bin in the middle, just the last folder. (method: copy the last folder, create a new folder on the disk, paste the last folder, and put the original compressed package in it)

                  2. Configure environment variables:

                        Step 1: open computer properties, click Advanced system settings, click environment variables,

Step 2: click Edit to configure Maven first_ Home, the variable value is the path from the previously extracted folder to the new folder, 

   Step 3: then find the path variable in the system variable, edit it, create a new one, and write% MAVEN_HOME%\bin  

 

    Step 4: verify. After configuration, mark mvn -version in cmd to verify whether it is configured (the figure shows that the configuration is successful)  

    3. Configure local warehouse and private warehouse (private warehouse here refers to Alibaba cloud warehouse)

                        1. Configure the local warehouse: open the newly unzipped folder, click it, click the conf directory, click settings.xml to change it, click it, press ctrl+F to query the local, find the local and change it to the figure below:

          2. Configure the image warehouse: search for a mirror in settings.xml to make changes: change the above mirror to the following one   

In this way, the local warehouse and Alibaba cloud warehouse are configured.

5: What problems have been solved:
Using maven solves the problem that you don't have to import jar packages manually.

6, Practical operation: run maven project
Steps:
          1. Enter eclipse to configure maven, click windows - > preferences, then search maven, click installations in maven, click Add to find your Maven folder, and then add the folder.

   2. Under the same panel, click User Settings, and then add settings (local warehouse) under conf file under maven folder 

  3. After creating a new project, an error will be reported (very normal). First, delete the index file under webapp in main under src. I deleted it at that time.  

       4. Then, right-click the newly created project, click Properties, find Project Facets, find java, change the version from 1.5 to 1.8, then use and close it, and then repeat the above operations, find the Dymamic web module, and change the version from 2.3 to 3.1. Note: cancel the check of Dymamic web module, then run and close it, Then enter the interface and check it. A line of English sentence will appear below. Click to change webcontent to webapp.

 

       5. Change the content in web.xml: change the code from to the following:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  <display-name>Archetype Created Web Application</display-name>
</web-app>

 

   6. Change the content in pom.xml: to change the version from 3.8.0 to 4.0.0:

                  Search the website www.mvnrepository.com in the browser. After entering, search for servlets in the search box and click Java Servlet API 4.0.0  

Then click maven to copy the code in maven to pom.xml

 

  After pasting it, the corresponding file will be downloaded. It takes a few minutes.

 

    7. After completing the above operations, create a new package in the / src/main/java directory and then create a class:

  After that, the results will appear after running with tomcat. The printing statement indicates that the project is successfully run with maven   

 

      8. Note:

                  1. When contacting maven project, the network must be connected, and the network quality is good.

                  2. MAVEN projects have no dependencies by default

            9. Import complete dependencies: (write the following code to the pop.xml file and wait for the download to complete)

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
 
    <!--add to jar Package dependency-->
    <!--mysql-->
    <mysql.version>5.1.44</mysql.version>
    <!--5.other-->
    <junit.version>4.12</junit.version>
    <servlet.version>4.0.0</servlet.version>
    <jackson.version>2.9.3</jackson.version>
    <jstl.version>1.2</jstl.version>
    <standard.version>1.1.2</standard.version>
    <tomcat-jsp-api.version>8.0.47</tomcat-jsp-api.version>
    <commons-beanutils.version>1.9.3</commons-beanutils.version>
    <dom4j.version>1.6.1</dom4j.version>
    <jaxen.version>1.1.6</jaxen.version>
 
  </properties>
 
  <dependencies>
    <dependency>
      <groupId>jaxen</groupId>
      <artifactId>jaxen</artifactId>
      <version>${jaxen.version}</version>
    </dependency>
 
    <dependency>
      <groupId>dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>${dom4j.version}</version>
    </dependency>
 
 
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>${commons-beanutils.version}</version>
    </dependency>
 
    <!--mysql-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
    </dependency>
 
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
 
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>${servlet.version}</version>
      <scope>provided</scope>
    </dependency>
 
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>${jackson.version}</version>
    </dependency>
 
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>${jstl.version}</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>${standard.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-jsp-api</artifactId>
      <version>${tomcat-jsp-api.version}</version>
    </dependency>
 
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.10</version>
      <scope>provided</scope>
    </dependency>
 
    <dependency>
      <groupId>com.belerweb</groupId>
      <artifactId>pinyin4j</artifactId>
      <version>2.5.0</version>
    </dependency>
 
    <dependency>
      <groupId>com.github.davidcarboni</groupId>
      <artifactId>encrypted-file-upload</artifactId>
      <version>2.1.0</version>
    </dependency>
  </dependencies>

Posted by hamboy on Wed, 13 Oct 2021 07:39:39 -0700