DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Approach Dependency Management in Java [Video]
  • My Experiences with Maven in IntelliJ IDEA and NetBeans IDE
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • Tracking Dependencies Beyond the Build Stage

Trending

  • Stop Using Python for Your GenAI Apps, Use Go and Genkit Instead
  • Designing Effective Meetings in Tech: From Time Wasters to Strategic Tools
  • We Went Multi-Cloud and Almost Drowned: Lessons From Running Across AWS, GCP, and Azure
  • Why AI Forces a Rethink of Everything We Know About Software Security
  1. DZone
  2. Coding
  3. Java
  4. Importing a Maven Project in IntelliJ IDEA

Importing a Maven Project in IntelliJ IDEA

Click here to learn more about importing a Maven project in IntelliJ IDEA.

By 
Alejandro Duarte user avatar
Alejandro Duarte
DZone Core CORE ·
Updated Sep. 29, 20 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
51.9K Views

Join the DZone community and get the full member experience.

Join For Free

Maven Project in IntelliJ IDEA

Importing a Maven project in IntelliJ IDEA

This tutorial explains how to import an existing Maven project into IntelliJ IDEA and how to create a running configuration for a Maven goal. This is useful, for example, when using the Jetty Maven plugin that allows you to quickly deploy and run a Java web application using this popular server.

Maven is a project management tool that goes beyond dependency management. See Learning Maven Concepts to learn more.

Download an Existing Maven Project

This tutorial uses a Maven archetype that generates a web application with a preconfigured Jetty Maven Plugin in it:

mvn -B archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=LATEST -DgroupId=org.test -DartifactId=webapp -Dversion=1.0-SNAPSHOT


NOTE: If you prefer, you can generate a ZIP file with the project at https://vaadin.com/start/latest or https://start.vaadin.com. Make sure you select the Plain Java Servlet option before downloading the project.

The project should include a directory with a Maven project in it:

Maven project directory

NOTE: You need Node.js installed on your computer to compile the example application.

Import the Project

There are several ways to import a Maven project in IntelliJ IDEA. The most common approach is to open the pom.xml file directly. You can do it in the welcome screen by clicking Open:

Welcome screen

NOTE: Import Project gives you more options to tweak the import process. However, this is out of the scope of this tutorial.

Select the pom.xml file of the Maven project you want to import and click Open as Project.

NOTE: The welcome window is only shown when you close all projects in IntelliJ IDEA. If you don’t want to close your currently opened projects, you can select File > Open on the menu instead.

Running Maven Goals

IntelliJ IDEA has excellent integration with Maven. You can run common commands such as mvn install or mvn jetty:runwithout having to leave the IDE.

Open the Maven view by clicking the corresponding option on the left side of the IntelliJ IDEA window:

Maven projects view

This view shows all the available Maven projects and their build phases and build goals. Let’s say you want to run mvn install. To do that, expand the project tree in the Maven view to show the corresponding lifecycle phase and then double-click install:

Lifecycle phases

You’ll see how IntelliJ IDEA executes the install build phase (and all the previous phases in the Maven’s default lifecycle) that downloads dependencies and copies the generated artifacts into your local Maven repository, among other things.

You can use a similar approach to run any Maven goal. For example, you can double-click the jetty:run goal in the Plugins sub-tree to deploy and run the web application implemented in the project you imported. Similarly, if you are using Spring, you can double-click spring-boot:run to run the application.

Creating a Running Configuration

Since using the jetty:run goal could be a frequent task during the development of a Java web application, you may prefer to create a running configuration for it.

A running configuration is a shortcut to run a specific task from within the IDE. Let’s create a running configuration for the jetty:run Maven goal to make it simpler to run the web application.

Right-click the jetty:run option in the Maven view and select Create 'webapp [jetty:run]':

Create running configuration option

For simplicity, change the name of the configuration to Run on Jetty and click OK:

Run on Jetty

NOTE: If you are using a multi-module Maven project, make sure you select the correct module when creating the running configuration.

You should see the new option on the top right corner of IntelliJ IDEA:

Running configuration created

Now you can deploy and run the web application by clicking the run (or the debug) icon in the toolbar:

Run icon

NOTE: If you use the Vaadin project used in the tutorial, you can invoke the web application at http://localhost:8080.

That’s it. Now you can use IntelliJ IDEA to develop your Maven application!

Further Reading

10 Effective Tips on Using Maven

intellij Apache Maven Web application

Published at DZone with permission of Alejandro Duarte. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Approach Dependency Management in Java [Video]
  • My Experiences with Maven in IntelliJ IDEA and NetBeans IDE
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • Tracking Dependencies Beyond the Build Stage

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook