English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Maven IntelliJ

IntelliJ IDEA has built-in support for Maven. In this example, we are using IntelliJ IDEA Community Edition. 11.1.

The following are some features of IntelliJ IDEA:

  • You can run Maven goals through IntelliJ IDEA.

  • You can view the output of Maven commands in IntelliJ IDEA's own terminal.

  • You can update Maven dependencies in the IDE.

  • You can start Maven builds in IntelliJ IDEA.

  • IntelliJ IDEA implements automated dependency management based on Maven's pom.xml.

  • IntelliJ IDEA can resolve Maven dependencies through its own workspace without installing them in the local Maven repository, although the dependent projects are in the same workspace.

  • IntelliJ IDEA can automatically download the required dependencies and source code from the remote Maven repository.

  • IntelliJ IDEA provides a wizard to create Maven projects and pom.xml files.

Create a new project in IntelliJ IDEA

Use the New Project wizard to import a Maven project.

  • Open IntelliJ IDEA.

  • Select File Menu > New Project Options.

  • Select import project from existing model Options.

  • Select Maven Options.

  • Select the project path, which is the storage path when creating a project with Maven. Suppose we created a project consumerBanking. By Maven Build Java Project See how to create a project using Maven.

  • Select the Maven project to import.

  • Enter the project name and click "finish".

Now, we can see the Maven project in IntelliJ IDEA. Look at the Libraries and Test Libraries of the consumerBanking project, and you will find that IntelliJ IDEA has added all the dependencies required by Maven to its build path.

Build a Maven project in IntelliJ IDEA

Alright, let's use the compilation feature of IntelliJ IDEA to build this Maven project next.

  • Select the consumerBanking project.

  • Select Build menu > Rebuild Project Options.

You can see the log output of the build process in the IntelliJ IDEA terminal:

4:01:56 PM Compilation completed successfully

Run the application in IntelliJ IDEA

  • Select the consumerBanking project.

  • Right-click on App.java to pop up the context menu.

  • Select Run App.main() .

You will see the following running results in the IntelliJ IDEA terminal:

"C:\Program Files\Java\jdk"1.6.0_21\bin\java"
-Didea.launcher.port=7533 
"-Didea.launcher.bin.path=
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1.2\bin"
-Dfile.encoding=UTF-8 
-classpath "C:\Program Files\Java\jdk"1.6.0_21\jre\lib\charsets.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\deploy.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\javaws.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\jce.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\jsse.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\management-agent.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\plugin.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\resources.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\dnsns.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\localedata.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunjce_provider.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunmscapi.jar;
C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext\sunpkcs11.jar
C:\MVN\consumerBanking\target\classes;
C:\Program Files\JetBrains\
IntelliJ IDEA Community Edition 11.1.2\lib\idea_rt.jar" 
com.intellij.rt.execution.application.AppMain com.companyname.bank.App
Hello World!
Process finished with exit code 0