Sunday, October 17, 2010

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

4 comments:

  1. ... or you could just go to "File->Open Project" in Intellij (9 and 10) and select the pom.xml file in your project.

    ReplyDelete
  2. Netbeans need only pom.xml file. No other files are required, then every maven project is netbeans ready :-)

    ReplyDelete
  3. @Hohonuuli: Thank you for the comment.Yes, I noticed that functionality while working on the demo project. But forgot to add it. Thank you for bringing it up!!! I will update the blog.

    ReplyDelete
  4. @arpi_79: Thank you for the comment. The readers of this blog will definitely find that helpful. :-)

    ReplyDelete

Your comments are welcome. It will help me improve my communication and content...plus it will encourage me! :-)