1. Maven creates jar package project
Requirements: Use Maven to create jar package projects.
- Click
New Project
, selectmaven
, and then clickNext
, as shown in Figure 1-1. - 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.
- Choose a project location, note that IDEA will not automatically generate the corresponding folder for your project name, as shown in Figure 1-3.
- There are lower corner in the displayed dialog box, select
Enable Auto-Import
automatically import Maven configuration, shown in 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/java
writing 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.xml
adding 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>
复制代码