Maven: Using with Eclipse and IDEA
Approach using M2Eclipse plugin for Eclipse
We recommend using the M2Eclipse Plugin for Maven in Eclipse.
Prerequisites
Ensure you have the most current versions of the following:
- Eclipse Classic version of the Eclipse IDE: http://www.eclipse.org/downloads/
- Eclipse XML Editors and Tools
- M2Eclipse Plugin
Install Eclipse XML Editors and Tools
-
Go to Help > Install New Software:
-
Select the Galileo update site and choose the Eclipse XML Editors and Tools:
Install the M2Eclipse Plugin
-
Use the same facility to add the M2Eclipse tools. Click Add and enter the M2Eclipse update site URL: http://m2eclipse.sonatype.org/update/.
-
Select the first group to include all of "Maven Integration". Your IDE will restart several times during this process.
Project Setup in Eclipse
From an empty or existing workspace, choose File > Import or right-click on the Package Explorer pane and select Import. Select to import Maven Projects:
M2Eclipse will detect all the pom files and generate the project structure. Create a New Java working set from this:
Click on the Advanced options and add a template name to tie each Maven module to your project, for example, Acme-[artifactId]
.
Congratulations, your project has been created! Now when you build, Eclipse will use the Maven compile configuration.
Where are my sources?
Sources are stored in Maven source jars. To download and link these in your IDE:
- Right-click on your pom > Maven > Download Sources.
This should pull the dependency sources and link them up. Test by pulling up a Jive class, such as LoginAction
(cmd+shift+T) and verify the source is present.
Handling .ftls and other war file sources
If you have downloaded a source build, reference those source files by creating a new working set. The simplest approach is to include your war target directories in the project configuration, which happens by default unless explicitly hidden. To hide target directories from an index search, right-click on the web/target directory in your package explorer, click Properties, and check the Derived checkbox:
Maven-only alternative method
It is possible to use Maven with Eclipse without the M2Eclipse tool. From the root of your project, run:
mvn eclipse:clean eclipse:eclipse -DdownloadSources=true
This refreshes your existing Eclipse project files and links up your sources. Then, from a fresh workspace, import the root directory as an existing project.
Using Maven with IDEA
This section provides the steps for opening and running your new project with IntelliJ IDEA.
Assumptions
This document assumes you have set up your Maven project from the command line, as described in Maven: Creating new project.
Step 1: Create New IDEA Project
-
From the home screen or the menu, select File > Open Project.
-
Navigate to the Maven source code your archetype has created and select the root
pom.xml
file:
This will mostly handle the build and configuration of your project.
Step 2: Download Your Dependencies
You can download dependencies from the command line or from IDEA:
-
Command Line: From the project root, run:
mvn dependency:sources
-
IDEA: Hit the Update Folders button in the Maven Projects tab, or click Download Artifacts to link everything in one step:
Action Description Update Folders (used if you ran mvn dependency:sources
on the command line)Download Artifacts (use alone; may take time)
When complete, the source code for all dependencies, including the application source, will be available during coding and debugging. Test by looking up the LoginAction
Java class to verify full source code availability.
Tips for Optimal Use: Avoid File Re-indexing
To prevent file re-indexing, set IDEA to maintain its own compile output. Select "Inherit project compile output path" in your Project Settings: