4.1 maven summary

  • 1. maven usage

      Regarding the description of maven, there is a lot of talk on the Internet, and it is also abstract. In fact, the main uses of maven can be divided into two categories:

      • 1) Build the project and quickly download the packages required by the project - download function
      • 2) Project management functions such as publishing projects to the server - management functions

      In actual operation, maven only needs to configure the pom.xml of the maven project, and it can be downloaded quickly, which is very convenient. Of course, the premise is to use the domestic mirror.

 

  • 2. maven configuration  in myeclipse
      • 1) Download, unzip
      • 2) Add MAVEN_HOME environment variable
      • 3) Modify the maven subfolder conf/setting.xml, modify the lib library location and mirror
      • 4) Menu window->preferences->myeclipse->maven4myeclipse->user settings, configure the setting.xml file path modified in the previous step

  • 3. Little knowledge of maven+myeclipse
      • 1) maven project + local tomcat + myeclipse, three local running methods:
    • ① Right-click the project run on server, and create a new local tomcat copy running project (the project here can be found in the default deployment path of myeclipse, which can be seen from the startup log) - recommended;
    • ② In the servers tab, right-click Tomcat7.x, deploy through add deployment..., which is to deploy the code to the local tomcat through myeclipse, and click to run the tomcat.
    • ③ Start the local tomcat first, and then publish the code to the local tomcat by right-clicking the project maven build->tomcat7:deploy (in this way, you need to configure the user and password for accessing tomcat in maven or project pom.xml) ;
 
      • 2) maven's groupid and artifactId
    •  The groupid and artifactId are collectively referred to as "coordinates", which are proposed to ensure the uniqueness of the project. If you want to get your project to the maven local warehouse, you must search according to these two ids if you want to find your project.
    • The groupId is generally divided into multiple segments, here I only mention two segments, the first segment is the domain, and the second segment is the company name. Domains are divided into org, com, cn, etc., among which org is a non-profit organization and com is a commercial organization. Take the tomcat project of apache company as an example: the groupId of this project is org.apache, its domain is org (because tomcat is a non-profit project), the company name is apache, and the artigactId is tomcat.
    • For example, if someone creates a project, they usually set the groupId to cn.zr, cn means the domain is China, zr is the personal initials, and the artifactId is set to testProj, which means that the name of the project is testProj. According to this setting, the best package structure is Started with cn.zr.testProj, if there is a StudentDao, its full path is cn.zr.testProj.dao.StudentDao
      • 3) Common maven commands
    • mvn archetype:create creates a Maven project
    • mvn compile compile source code
    • mvn deploy publishes the project
    • mvn test-compile compile test source code
    • mvn test to run unit tests in the application
    • mvn site to generate project-related information
    • mvn clean cleans the build results in the project directory
    • mvn package generates a jar based on the project
    • mvn install installs the jar in the local Repository
    • mvn eclipse:eclipse generates eclipse project files
    • mvnjetty:run start jetty service
    • mvntomcat:run starts the tomcat service
    • mvn clean package -Dmaven.test.skip=true: Repackage after clearing previous packages, skip test classes
    • dependency:tree
        It is also necessary to pay attention to the version problems of maven and tomcat. For example, version 2.2 of tomcat7-maven-plugin requires the minimum tomcat version to be tomcat8, and tomcat also has requirements for JDK, so before downloading, you must first find out whether the version is compatible. Don't waste time.
 
 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327034018&siteId=291194637