Maven in IntelliJ
IntelliJ IDEA has built-in support for Maven. In this example, we are using IntelliJ IDEA Community Edition 11.1.
Some features of IntelliJ IDEA are listed below:
- 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 within the IDE.
- You can start Maven builds in IntelliJ IDEA.
- IntelliJ IDEA manages dependencies automatically based on Maven's pom.xml.
- IntelliJ IDEA can resolve Maven dependencies through its workspace without needing to install them in the local Maven repository, as long as the dependent projects are in the same workspace.
- IntelliJ IDEA can automatically download required dependencies and sources from remote Maven repositories.
- IntelliJ IDEA provides wizards for creating Maven projects and pom.xml files.
Creating a New Project in IntelliJ IDEA
Use the New Project wizard to import a Maven project.
- Open IntelliJ IDEA.
- Select File Menu > New Project.
- Choose import project from existing model.
- Select Maven.
- Choose the project path, which is the storage path when creating a project with Maven. Let's assume we have created a project named consumerBanking. Refer to Creating a Java Project with Maven for how to create a project with Maven.
- Select the Maven project to import.
- Enter the project name and click "finish".
Now, you 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 Maven dependencies to its build path.
Building a Maven Project in IntelliJ IDEA
Next, let's use IntelliJ IDEA's build functionality to build the Maven project.
- Select the consumerBanking project.
- Choose Build menu > Rebuild Project.
You can see the build process output in IntelliJ IDEA's terminal:
4:01:56 PM Compilation completed successfully
Running the Application in IntelliJ IDEA
- Select the consumerBanking project.
- Right-click on App.java to open the context menu.
- Choose Run App.main().
You will see the following output in IntelliJ IDEA's terminal:
``` "C:\Program Files\Java\jdk1.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\jdk1.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