U01_004 Maven creates jar package project

1. Maven creates jar package project

Requirements: Use Maven to create jar package projects.

  1. Click New Project, select maven, and then click Next, as shown in Figure 1-1.
  2. Fill in the horizontal and vertical coordinates. The horizontal coordinate is generally the inverted domain name of your company, and the vertical coordinate is generally the name of your project, as shown in Figure 1-2.
  3. Choose a project location, note that IDEA will not automatically generate the corresponding folder for your project name, as shown in Figure 1-3.
  4. There are lower corner in the displayed dialog box, select Enable Auto-Importautomatically import Maven configuration, shown in Figure 1-4.

Picture 1-1

Figure 1-2

Figure 1-3

Figure 1-4

2. Maven_jar project structure

项目名
    |_ src
        |_ main:源代码区
            |_ java:存放.java源代码
            |_ resources:存放资源文件
        |_ test:测试区
            |_ java:存放单元测试
    |_ pom.xml:Maven的核心配置文件
复制代码

3. Analysis of pom.xml file

<!-- xml文件头 -->
<?xml version="1.0" encoding="UTF-8"?>

<!-- pom.xml文件的根标签 -->
<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>

    <!-- 项目的横坐标:项目包名 -->    
    <groupId>com.joe</groupId>
    
    <!-- 项目的纵坐标:项目名 -->   
    <artifactId>HelloJava</artifactId>
    
    <!-- 项目的版本 SNAPSHOT是快照版-->
    <version>1.0-SNAPSHOT</version>

</project>
复制代码

4. HelloWorld

Requirements: In src/main/javawriting a class and run successfully.

Source code: HelloWorld.java

/**
 * @author JoeZhou
 * @version 1.0
 */
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("你好世界!");
    }
}
复制代码

Configuration: generated Maven need to change the source code and compile jdk version 1.8, in pom.xmladding file information was constructed as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
复制代码

Guess you like

Origin juejin.im/post/5e8c35c8e51d4546e14f4c08