Maven

Maven

1. Why learn Maven?

2. Maven project architecture management tool

At present, we are using to import jar packages:

Core idea: agreement is greater than configuration

Maven will specify how you should write our java code. You must follow this specification

3. Download and install maven

Official website http://maven.apache.org/

After downloading, unzip it

Suggestion: all environments on the computer are managed in one folder

4. Configure environment variables

In our system environment variables, the configuration is as follows:

Test whether the configuration is completed with MVN - version in CMD

5. Alibaba cloud image

<mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror> 

6. Local warehouse

Local warehouse, remote warehouse;

Set up a local repository: localrepository

<localRepository>D:\environment\apache-maven-3.6.3-bin\apache-maven-3.6.3\maven-repo</localRepository>

7. Use Maven in idea

8. Mark the source directory in idea

9. Start Tomcat

Where, application context writes / and accesses port 8080 by default

10. Maven's command line and plug-ins

11. POM documents

pom. XML is Maven's core configuration file

Such as importing spring

<!--Maven的高级之处在于,他会帮你导入这个jar包所依赖的其他jar包-->
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
    </dependencies>

Maven's agreement is greater than the configuration. We may encounter the problem that the configuration file we wrote cannot be exported or take effect. Solution:

<!--在build中配置resources,来防止我们资源导出失败的问题-->
<build>       
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>

            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
</build>

12. Solve the problem that JDK should be reset after updating Maven every time

Since Maven's default JDK is 1.5, you need to add the following code to the configuration file (I use jdk14)

    <!-- 这里一般有 maven 的默认配置,修改即可 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>
    </properties>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>