Maven build (useless time frame)

     Do steps to build, otherwise it will be a lot BUG.

     Each project will need to import the jar file, for example: oracle jar file about 2m, large jar files may be about 5-7m, very resource-intensive computer disk, it is best for each project has a configuration file, the introduction of information jar, and when we run the automatic configuration jar to help us, this is the Maven function.

download:

Official website: http://maven.apache.org/download.cgi, drop-down selection Binary zip archive to the first click to download

  1. Create a folder on the D drive, called ZCY_Maven, copy the zip file into the folder, and then unzip

  2, document presents:

   bin -> maven all commands are in it, companies do not command, there is a visual interface

   boot -> Start Resource (do not remove enough)

   conf -> Profiles

   lib -> project required jar files, as is written in java maven

   LICENSE, NOTICE -> configuration information

  3, use:

   1 Use Maven functions:

    Download the jar file:

      1, the remote repository: We need to download the resource (jar) files need a website, and this site is called a remote repository Maven

      2, the local repository: We will download jar files unity on this computer in a folder called local warehouse

      3, central warehouses: the enterprise is likely to jar files on your own server, our time of need can go to the central warehouse download

     Three warehouses relationship:

      1, after the jar file configuration, will go to a local warehouse to find whether there is this jar file,

      2, if there is no local repository JAR, to find a central repository (central repository is not configured then this step is omitted)

      3. If steps 1 and 2 can not find the jar file, go to remote repository to find whether there is a jar file

      

    Next, you need to configure in Maven:

     Local and remote warehouse warehouse

     Maven point to open the conf folder:

     Click to edit settings.xml

 

     1, configure the local warehouse:

      If no local repository, maven download the jar file is downloaded directly to the c drive, C drive is small, do not do it

      The default download path: C: \ Users \ admin \ .m2

      

      1.1. In ZCY_Maven create a file folder in a folder named repository

      1.2 Copy the repository folder path:. D: \ ZCY_Maven \ repository

      1.3 Open settings.xml

        Paste:

<localRepository>D:\英文命名的文件夹(不可带中文和数字,以免报错)\repository</localRepository>

 The content of which is the local repository file path

     

     2, configure the remote repository:

      We need to configure the domestic warehouse, so the speed is faster

       Ali made a remote repository       

 <mirror>      

         <id>alimaven</id>      

         <name>aliyun maven</name>      

         <url>http://maven.aliyun.com/nexus/content/groups/public/</url>      

         <mirrorOf>central</mirrorOf>        

        </mirror>
 切记粘贴在mirrors标签中

       

  3, because maven is very early in the product, the default jdk 1.5 version , so we need to modify the jdk version 1.8 changed 

    <profile>

       <id>jdk-1.8</id>

       <activation>

        <activeByDefault>true</activeByDefault>

        <jdk>1.8</jdk>

       </activation>

       <properties>

        <maven.compiler.source>1.8</maven.compiler.source>

        <maven.compiler.target>1.8</maven.compiler.target>

        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>

       </properties>

      </profile>

       切记粘贴在profiles标签中

 

    Because we need to use the Maven command a lot of programmers dislike, so we need to meet the Eclipse Maven visual interface jar file to download, so convenient 

    Eclipse and Maven configuration:

     Open Eclipse -> window -> preferences -> left sidebar to find Maven -> Found User Settings -> Global Settings to find the browse ... button clicks just to find a good settings.xml configuration file, and click OK -> click on update settings -> click Apply and Close to

    Note here, or will be error:

   

   Maven 2 functions use:

    Creating the Maven project:

     In the left sidebar, right -> new - project. . . -> Select the drop-down maven -> Select maven project -> click next - tick create a simple project ...--> Click next 

 -> Enter Group Id (package name) -> Enter Artifact Id (project name) -> Version modified to 0.0.1 -> packing select the WAR  -> Click Finish to

     

Next we will see the emergence of the maven project (here is to create a war of web project)

     See web engineering error   -> opening the src -> main -> webapp - > Right creation called WEB-INF folder -> Copy the code into web.xml deleted (and will not be used out, empty web.xml, with only basic configuration) -> I would not have the error.

     Note: If an error occurs, delete the local repository file , then delete the project, directly create project again until you create is successful.

  The local repository : file under (D \ ZCY_Maven \ repository) all deleted, re the above configuration -> window -> preferences -> left sidebar to find Maven -> etc.

    The first run a Maven project:

    Webapp created under a html file, for example: index.html file write hello Maven -> click the project name -> Right -> run as -> run on serve 

    Enter the browser: http: // localhost: 8080 / project name /index.html will be able to see results

    Maven highlights of the entire project in the pom.xml file

    

  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

      <modelVersion>4.0.0</modelVersion> 模块版本,就是pom.xml的版本,54即可

      <groupId>demo</groupId> 就是项目的包名

      <artifactId>project</artifactId> 项目名称

      <version>0.0.1</version> 项目版本

      <packaging>war</packaging> 项目的类型:jar-普通java项目,war-web项目

    </project>

    Import the jar:

   We are a local warehouse and consequently no need remote repository to download the corresponding jar file

    How to download it?

    All jar files have corresponding configuration information , as long as these strings to get configuration information (download link), you can go to download a remote repository

    Configuration information (links) how to find it?

    Find URL configuration information:

   https://mvnrepository.com/ or Baidu search maven first is

     

    We Maven project's Web servlet jar file does not need to download their own, is the need for configuration information (links)

     To download Servlet jar package as an example:

      1. Enter the URL to find the configuration information https://mvnrepository.com/

      2. In the search box, enter serlvet

      3. Locate the largest number of download links that click into 12,477 usages

      4. Select the Servlet corresponding version (the most recent)

      The replication configuration information   

   <dependency>

        <groupId>javax.servlet</groupId>

        <artifactId>javax.servlet-api</artifactId>

        <version>4.0.1</version>

        <scope>provided</scope>

       </dependency>

      6. In the web maven pom.xml file in the project:

      Create a <dependencies> </ dependencies> tag

      7. Copy the configuration information to the label, you can save downloaded from a remote repository

      8. We can create HttpServlet class in java

 

     Our web project needs which parameters to configure it?

     1.servlet     

<dependency>

       <groupId>javax.servlet</groupId>

       <artifactId>javax.servlet-api</artifactId>

       <version>4.0.1</version>

       <scope>provided</scope>

      </dependency>

      2.oracle   

  

  <dependency>

       <groupId>com.oracle</groupId>

       <artifactId>ojdbc6</artifactId>

       <version>11.2.0.4.0-atlassian-hosted</version>

      </dependency>

    3.fastjson     

 <dependency>

       <groupId>com.alibaba</groupId>

       <artifactId>fastjson</artifactId>

       <version>1.2.68</version>

      </dependency>

     4.mybatis     

 <dependency>

       <groupId>org.mybatis</groupId>

       <artifactId>mybatis</artifactId>

       <version>3.5.4</version>

      </dependency>

   Note: If there is a problem, then download <dependency> tags will report underlined in red, ( reasons: Network problems downloading timeout )

    solution:

      1. go to a local warehouse to the corresponding version of the folder to delete it

     2. Right-click on the project - maven - update project ... will be downloaded again

Published 163 original articles · won praise 92 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42995083/article/details/105374020