Build the MAVEN project under Mac OS X + idea-install MAVEN and Common MVN command introduction

Source: Internet
Author: User

The project that participates in the company is the Eclipse + maven under Windows. Want to play Maven on your computer, so here's the process of building a MAVEN project under Mac + idea.
First installs Maven:
1. Download the latest version of maven:https://maven.apache.org/download.cgi from the Apache web site, mac downloads. tar.gz
2. After decompression, Place the folder in the appropriate directory, e.g./users/sophie/ideaprojects/apache-maven-3.5.2
3. Configure path to add Maven Bin folder to path, first echo $ Path, and then add the Maven Bin folder path, separated by the previous path
sophie-mbp:/ sophie$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/x11/bin
sophie-mbp:/ sophie$ path=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/x11/bin:/users/sophie/ideaprojects/ Apache-maven-3.5.2/bin
sophie-mbp:/ sophie$ Echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/x11/bin:/users/sophie/ideaprojects/ Apache-maven-3.5.2/bin
4. Mvn-v Verify that you are working correctly

sophie-mbp:/ sophie$ mvn-v
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18t15:58:13+08:00)
Maven home:/users/sophie/ideaprojects/apache-maven-3.5.2
Java version:1.8.0, vendor:oracle Corporation
Java home:/library/java/javavirtualmachines/jdk1.8.0.jdk/contents/home/jre
Default LOCALE:ZH_CN, platform Encoding:utf-8
OS Name: "Mac OS X", Version: "10.13.2", Arch: "X86_64", Family: "Mac"

Then create the MAVEN project in idea: Idea > File > New > Project ... Select Maven on the left side, click Next to fill out groupid (according to custom, fill in the company/organization domain name), Artifactid (that is, the future package into Jar/war), click Next to fill out project name, click Finish

Idea will automatically create the Pom.xml file in the project root directory

<?xml version= "1.0" encoding= "UTF-8"?> <project "xmlns="
         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>ssophie.com</groupid>
    <artifactId>MavenTryOut</artifactId>
    <version >1.0-SNAPSHOT</version>
</project>

You can then add some other nodes under the project node, for example:

<packaging>jar</packaging>

It indicates that it will be packaged into a jar file.
Add some simple code to your project, such as writing a line of print output in main.
Next, in the terminal CD to the project root directory. Compiling projects with Maven

Sophie-mbp:maventryout sophie$ MVN Compile

At this point, {The project root directory}/target/classes/{package name}/should have. class file generation. Once again, go back to the project root, run the package command, and the. jar file will be generated in the target directory.

Sophie-mbp:maventryout sophie$ MVN Package

If you want to add your own project jar files to the local repository, run MVN install in the project root directory

Sophie-mbp:maventryout sophie$ mvn Install

The command runs with two lines of info output, which is to install the project's jar files and pom.xml into Maven's repo, and it will be available for other projects to be referenced in the future.

[INFO] Installing/users/sophie/ideaprojects/maventryout/target/maventryout-1.0-snapshot.jar to/users/sophie/.m2/ Repository/ssophie/com/maventryout/1.0-snapshot/maventryout-1.0-snapshot.jar
[INFO] Installing/users/sophie /ideaprojects/maventryout/pom.xml to/users/sophie/.m2/repository/ssophie/com/maventryout/1.0-snapshot/ Maventryout-1.0-snapshot.pom

The. M2 path is hidden by default, and you can command + Shift + if you want to display it in the Avatar interface. (both display and hide are the shortcut keys)

The following is the validation of whether the project's jar file was added to the MAVEN local repo path:

Sophie-mbp:maventryout sophie$ pwd
/users/sophie/.m2/repository/ssophie/com/maventryout
SOPHIE-MBP: Maventryout sophie$ ls
1.0-snapshot            maven-metadata-local.xml
sophie-mbp:maventryout Sophie$ CD 1.0- snapshot/
sophie-mbp:1.0-snapshot sophie$ ls
maventryout-1.0-snapshot.jar    _remote.repositories
Maventryout-1.0-snapshot.pom    Maven-metadata-local.xml

These commands, in fact, have menus in the idea IDE.
View > Tool Windows > Maven Projects
However, site and deploy did not use, do not understand what they are doing ...
╭ (╯_╰)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.