Installation and preliminary use of Maven
1. Download
2. Unzip the compressed package to your own hard drive, preferably in the root directory of a disk. For example, put it under the D drive.
3. Configure environment variables:
MAVEN_HOME: D:apache-maven-3.3.1
MAVEN: %MAVEN_HOME%bin
Add %MAVEN% to Path;
Win +R, enter cmd, enter the command line, enter mvn --version. The successful screenshot is as follows:
If it fails, it may be because there may be one more; or bin added to JAVA_HOME. As a result, JAVA cannot be found correctly. The failure screenshot is as follows:
4. The environment is configured, and it’s just the beginning. Now it’s time to add the maven plug-in to your eclipse.
Since various websites have been blocked by China, you cannot download and install plug-ins online. Therefore, it can only be replaced by various resources in the cloud. First, download the maven offline installation package of eclipse. Search online for yourself. . . . . . I wish you good luck in martial arts.
5. Then create two new folders, link and mavenplugins, under your own eclipse folder (name it yourself, just think about it) and extract the offline installation package into mavenplugins.
6. Create a maven.txt (name whatever you want) in the links directory, open it and enter:
path=D:adt-bundle-windows-x86_64-20140321adt-bundle-windows-x86_64-20140321eclipsemypluginsmaven (path is the address of the maven plug-in, please forgive me for the uninhibited address length).
7. Close maven.txt and change the suffix to link. Restart your eclipse.
8. Open Windows→Preferences and you will see the Maven navigation bar.
Click Installation→add to select the location of the maven you installed (not the address of the eclipse plug-in).
For example: D:apache-maven-3.3.1
Click User Setting→browse and add the location of your settings.xml.
For example: D:apache-maven-3.3.1confsettings.xml
9. Create a new project File→New→other→Maven→Maven Project. Just give the name of Group and Artifact after various Next.
10. Write the most classic code below, sayHelloWorld~~. Ignore the code, it is probably the function sayHello in App.java that outputs Hello, and then write a Test in AppTest to verify the sayHello function, assertEquals("Hello SPM!", result); and then right-click AppTest → Run As. As shown in the figure, the green bar indicates that the test passed.
~~~~~
And from the build output, I discovered a major advantage of maven3. The build output is more clear:
Maven3 output
[INFO] Building Nexus (API) 1.4.1-SNAPSHOT
[INFO] -------------------------------------------------- --------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.2:clean (default-clean) @ nexus-api ---
[INFO] Deleting directory /home/juven/workspaces/ws-nexus/nexus/nexus-api/target
[INFO]
[INFO] --- maven-resources-plugin:2.4:resources (default-resources) @ nexus-api ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/juven/workspaces/ws-nexus/nexus/nexus-api/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ nexus-api ---
[INFO] Compiling 191 source files to /home/juven/workspaces/ws-nexus/nexus/nexus-api/target/classes
[INFO]
[INFO] --- plexus-component-metadata:1.2.1:generate-metadata (process-classes) @ nexus-api ---
[INFO] Discovered 1 component descriptors(s)
[INFO]
[INFO] --- maven-resources-plugin:2.4:testResources (default-testResources) @ nexus-api ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/juven/workspaces/ws-nexus/nexus/nexus-api/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ nexus-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- plexus-component-metadata:1.2.1:generate-test-metadata (process-test-classes) @ nexus-api ---
Install maven eclipse plug-in offline
1. Create a new maven.link file in the dropins directory under the eclipse directory. The file name is not restricted.
2. Point to the maven plugin in the maven.link file: path=../myplugin/maven3
3. Restart eclipse, window->Preferences, find the maven tag and set it
it works
it works
it works