Opening Maven Projects is Easy as Pie

Maven integration in a Java IDE might not be a surprise for you, but let me show you just one thing, that makes IntelliJ IDEA Maven support prominent and noteworthy.

If you have any Maven project, you do not need to perform routine steps while importing it to IntelliJ IDEA and you do not need to be anxious about dependencies and artifacts in it, nor would you need to worry about technologies used in project. Just open the project as you do with usual IntelliJ IDEA projects, sit back and relax. IntelliJ IDEA will automatically recognize everything.

Here is an example. To open our Maven project, we just go to File | Open Project (Alt + F + O) and specify the path to pom.xml (the Maven project descriptor file).

Select Path dialog

IntelliJ IDEA creates a project based on the Maven Project descriptor file.
When done, all maven goals can be found in the Maven projects tool window. We can simply run/debug arbitrary Maven goals; execute them before/after make or run/debug, or by invoking an assigned keyboard shortcut. Select any Maven goal in the tree and right-click it to view options.

Run Maven Goal

Now, let’s view our project structure. Go to Settings (Ctrl + Alt + S) | Project Structure and click Modules. As you can see, IntelliJ IDEA recognized modules and web facets. Moreover, all dependencies and deployment settings were detected and stored.


That’s all, nothing but a single click and you can enjoy complete support for Maven builder, including smart coding assistance for editing Maven pom.xml, intelligent code completion, inspections and quick-fixes, refactorings and other IntelliJ IDEA productivity-boosting features, which we are going to cover in the next posts.

Technorati tags: , ,
This entry was posted in Tips & Tricks. Bookmark the permalink.

22 Responses to Opening Maven Projects is Easy as Pie

  1. Souk says:

    I work a lot with maven and Idea, works great, but I have one small question: is there a way to have Idea remember that the “target” folders are ignored, even when I do a “mvn clean” via the command line ? Usually, doing this just kills the “ignore” settings and I have to go through the Project settings > modules > set target folders to ignore all over again

  2. Anton Makeev says:

    Unfortunatelly we cannot exclude target directory since it may contain generated sources. All the directories under the target are exluded, though.
    The 8.0 eap and forthcoming 7.0.4 eap feature improved handling of target directory. You may try them both.

  3. Jeremy Leipzig says:

    I don’t understand why the maven plugin doesn’t inform IntelliJ of where it is putting the dependencies. When I go to the dependency tab all the jars are red and cannot be edited (the edit button does nothing and the navigate right-click option is greyed out). I have to manually find them and add them to my global library to do any real work.

  4. Anton Makeev says:

    All the dependencies are resolved and downloaded during importing and are put in the maven’s repository (by default in ~/.m2). If you have ‘red’ dependencies, it must be something wrong with either pom or repository.

    You may write me on ‘Anton dot Makeev at jetbrains dot com’ and describe you problem in details.

  5. Jeremy Leipzig says:

    they are downloaded and placed in your repository but those dependencies are not placed into IntelliJ’s global libraries
    so you can build a Maven project and run through its goals without issue but to properly develop an application further you need to manually build your global library based on where Maven put those dependencies in your repository or copy the source’s application library config file
    this is not an optimal solution

  6. Anton Makeev says:

    Maven dependencies are not supposed to be placed into any global library: they are configured as module libraries. Could you send me your pom file and some screenshots on ‘Anton dot Makeev at jetbrains dot com’ so I could understand the problem?

  7. Darin Manica says:

    I really like the pom support in Idea, but I’m having trouble with HotSwap in the debugger. When I compile just a single file (ctrl + shift + F9), it appears to be running a maven target, which triggers a reload of my webapp. I really want to just compile the file and have it HotSwap without triggering anything from Maven. Is this possible?


  8. Anton Makeev says:

    I don’t quite understand you.
    Do you want to automatically run hotswap after executin maven goal?
    If it’s so you may vote for and watch
    We’ll implement it in one of the following eaps.

  9. Darin Manica says:

    I don’t want to run hotswap after executing a maven goal, I want to be able to compile a single file and hotswap it without running any maven goals. For example, say that I run “maven package” to build a .war file and start my app server. Then I make a change to a java file. I’d like to compile that single file in Idea and have it hotswap. Currently, when I run “Compile (ctrl+shift+F9)” it runs a maven goal that regenerates the war file instead of just compiling the single file and hotswapping it. The problem is that redeploying the war file is too slow and doesn’t always work (and defeats the purpose of hotswap.)

    I used to do this exact behavior, when using running “mvn idea:idea” and having maven generate my project/module files. For some reason, when I switched over to using the pom as the project file, I lost this functionality. Otherwise, I prefer using the pom support, so I’m hoping it is possible to hotswap a single file without running maven targets.

  10. Anton Makeev says:

    Compilation with SHIFT+CTRL+F9 does not run maven goal: it runs the native idea compilation process; this process involves regeneration of the war file, though.
    I could recommend you to use an exploded directory instead of the war if you want to have a quick hatswap.
    If you want any details, please mail me to Anton dot Makeev at jetbrains dot com.

  11. Dan Delorey says:

    I am having trouble debugging maven goals. I can run individual goals by double-clicking them or by selecting “Run Goal” from the context menu. However, if I select “Run ‘project_name [goal_name]‘” or “Debug ‘project_name [goal_name]‘” from the context menu, I get an error “Error running Tests: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.” I have set the home directory on the configuration dialog. Can you give me any other pointers?

  12. Anton Makeev says:

    Unfortunately at the moment you have to specify an installation path for the Maven Run Configuration itself: the Maven Settings do not affect Run Configurations.
    This inconsistency will be fixed in next versions.

  13. Jigar Gosar says:

    I have an idea project in which i have couple of modules each of which has a maven pom file. Now if I want to compile the project from within idea I have to manually add each and every library into idea project. How can i tell idea to add all maven dependencies for each module in its configuration so that i can compile projects from within idea.

    Basically, I want that every time I add a dependency in pom file it should also be included in the module dependency, is there any easier way to achieve this?

  14. Jeremy Leipzig says:

    Jigar Gosar: You want the Maven Dependency Sync plugin.
    That is what I was looking for myself as you can see several posts above. I don’t know why this is not a built-in feature.

  15. Axel Wagner says:

    @Dan Delorey & @Anton Makeev

    bug in .idea/workspace.xml:

    after import a maven project just add:

    and modify by setting a mavenHome variable in

  16. HappySpaceInvader says:

    Why does IntelliJ still not pick up the $M2_HOME I have set in my system. When trying a Maven build, I get the error “No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.”, yet when I run “echo $M2_HOME” in my Terminal, I can see that the environment variable is correctly set (to /usr/share/maven in my case”.

  17. Chad says:

    I ran into the same problem where intelliJ was not picking up the $M2_HOME variable set for my linux environment. One workaround is to modify the file and add the following:

    export M2_HOME=[path/to/maven2]

  18. lilly says:

    I used IntelliJ an a maven project for a while, and It’s pretty easy to load the maven project. Suddenly the IDE couldn’t load the libraries automatically from local maven repository. project structures->Libraries is empty when I load a new maven project.

    I reinstalled community version 11.0.2, and tried to reconfig, but still couldn’t load any library Jar files
    I check that settings=>Maven=>Repositories have correct local repository location.

    May you please help? Thanks a lot!

  19. Gul says:

    I have used IntelliJ Idea Ultimate 10.5.4 build #IU-107.777 for maven projects for a while and it usually was pretty easy to load maven projects. All of sudden the IDE couldn’t load the libraries automatically from local maven repository. I have checked Project setting -> Maven -> Repositories have the correct configuration. Even when I start maven build by selecting a goal (e.g. ‘clean’), this does not do anything even when left to run for hours. I am on Windows 7 Professional 64-bit and I have configured IDEA to use local drive for configuration storage.

    Wondering if there is an issue with the Idea build?

    The maven build from command line works fine.

  20. hevora says:

    Open project settings, and make sure M2_HOME is set there correctly.

  21. Gul says:

    hevora: All settings related to maven in Idea IDE File -> Settings -> Maven are set correctly including Maven home directory, User settings file and Local repository point to the correct configuration. The maven still cannot resolve dependencies.

  22. Rod says:

    I was willing to buy it right now because it promises to work out of the box for Java EE development, but Maven project integration is broken. Another buggy IDE. If I must pay it could at least work. I’m really pissed, disappointed….whatever.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>