Create the first HelloWorld with maven
1. Download apache-maven
and enter the official website , click download, download the zip file
, create a file apache-maven, unzip the zip file, and then create a LocalRepository file for the local warehouse (my own path F:\apache-maven\ )
2. Open the idea, open the settings File->Settings,
select Build, Execution, Deployment->Build Tools->Maven,
one item on the right of the Maven home directory in Maven...you can choose apache-maven, and the zip file you just downloaded
is in F :\apache-maven\apache-maven-3.6.3\conf under settings.xml to set
(1) Set the location of the local warehouse
<localRepository>F:\apache-maven\LocalRepository</localRepository>
(2) Set mirroring
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name> <url>https://maven.aliyun.com/repository/public</url>
</mirror>
(3) set profile
<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>
(Using the settings.xml that comes with idea by default can also be used, the same setting, the address is plugins->maven->lib under the idea download directory, and the following two select two mavens) Details point 1: work offline remove the tick
Details
2 :Import maven projects automatically ticked under importing, and automatically downloaded sources and documentation are also ticked
3. Create a test
Create a new module File->New->Module
and select maven. You need to select jdk1.8 when opening it for the first time, and then
fill in the GroupId in the next step
Create a project name Hello with ArtifactId,
create a class Hello under src->main->java, write a sayHello method,
create a test method under test->java
, and find that idea automatically adds sentences, and all maven projects on the right report errors under plugins I
clicked install under Lifecycle to try to install and found an error
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6: 1 problem was encountered while building the effective model
[ERROR] [FATAL] Non-parseable POM F:\apache-maven\LocalRepository\org\apache\maven\plugins\maven-resources-plugin\2.6\maven-resources-plugin-2.6.pom: unexpected markup <!d (position: START_DOCUMENT seen \r\n<!d... @2:4) @ line 2, column 4
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
Click Execute Maven Goal, enter the following command, update the incomplete command
-U idea:idea
Trying various commands under Lifecycle, I found that errors were reported, and errors were still reported under Plugins
. I found a lot of errors on the Internet, and there were basically no complete errors~ _ ~
My own method: enter the package name under pom.xml Go in (note the version)
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</dependency>
Add three packages under modules
and the test is complete
idea packaging jar package
Open maven, select clean, compile and install in turn