Maven: Make project IntelliJ Idea/Eclipse ready

With Maven it is pretty simple to make a project importable into IntelliJ Idea/Eclipse/Netbeans IDE. In this post I will cover IntelliJ Idea and Eclipse only.

For IntelliJ Idea: The easiest way is to choose: New Module -> Import Module from External Model and give it the project's root directory. But I believe this functionality has been recently added to IntelliJ Idea, which means it might not be available with pre Idea-X EAP._ (I could be wrong here.)_

UPDATE: As Hohonuuli pointed out in the comments, you can also do File -> Open Project, and select the pom.xml file in your project in Intellij (9 and 10).

For whom IntelliJ Idea does not provide this functionality based on the Idea version they are on, they can run a maven command to generate IntelliJ related files:

rhasija@rhasija-desktop $ mvn idea:idea

rhasija@rhasija-desktop $ ls -lart  
total 72  
drwxr-xr-x 3 rhasija rhasija  4096 2010-10-05 22:40 src  
-rw-r--r-- 1 rhasija rhasija   791 2010-10-05 22:40 pom.xml
drwxr-xr-x 8 rhasija rhasija  4096 2010-10-05 22:49 ..  
drwxr-xr-x 3 rhasija rhasija  4096 2010-10-05 22:50 target  
-rw-r--r-- 1 rhasija rhasija 20933 2010-10-05 22:58 MavenSpringHibernateMockitoDemo.iws
-rw-r--r-- 1 rhasija rhasija  4535 2010-10-05 22:58 MavenSpringHibernateMockitoDemo.ipr
-rw-r--r-- 1 rhasija rhasija  3855 2010-10-05 22:58 MavenSpringHibernateMockitoDemo.iml
-rw-r--r-- 1 rhasija rhasija    47 2010-10-05 22:59 .gitignore
drwxr-xr-x 5 rhasija rhasija  4096 2010-10-05 22:59 .  
drwxr-xr-x 8 rhasija rhasija  4096 2010-10-05 23:00 .git

Notice the MavenSpringHibernateMockitoDemo.iws, MavenSpringHibernateMockitoDemo.ipr, and MavenSpringHibernateMockitoDemo.iml files.

This will add Idea related files project.ipr, project.iws, and project.iml.

To make project Eclipse ready run the following maven command:

rhasija@rhasija-desktop $ mvn eclipse:eclipse

rhasija@rhasija-desktop $ ls -lart  
total 32  
drwxr-xr-x 3 rhasija rhasija 4096 2010-10-05 22:40 src  
-rw-r--r-- 1 rhasija rhasija  791 2010-10-05 22:40 pom.xml
drwxr-xr-x 8 rhasija rhasija 4096 2010-10-05 22:49 ..  
drwxr-xr-x 8 rhasija rhasija 4096 2010-10-05 22:50 .git  
drwxr-xr-x 3 rhasija rhasija 4096 2010-10-05 22:50 target  
-rw-r--r-- 1 rhasija rhasija  428 2010-10-05 22:50 .project
-rw-r--r-- 1 rhasija rhasija  317 2010-10-05 22:50 .classpath
drwxr-xr-x 5 rhasija rhasija 4096 2010-10-05 22:50 .  

Notice the .project and .classpath files in the directory