Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Eclipse is by far and away the most popular IDE among Java developers.

Table of Contents

  1. Download and Install
  2. Integration with WTP
  3. Debugging
  4. Spring Support
  5. Tips and Tricks

Download and Install
Anchor
download
download

Wiki Markup
{div:style=float:right}!eclipse-logo.jpg!{div}
To make your project Eclipse-aware, perform the following steps:

  1. Read Development Environment for additional configuration information.
  2. Download Eclipse 3.2 or Eclipse 3.3Rc2 and use Callisto (Software Update) to get plugins for developing web and database-driven applications.
  3. Install Eclipse into $TOOLS_HOME/eclipse-3.2.
  4. When starting Eclipse, set your workspace directory to C:\Source on Windows and ~/dev on *nix.
  5. In your project's directory, run mvn eclipse:eclipse. This will generate project files using the Maven Eclipse Plugin. If you're using a modular archetype, you may need to run mvn install eclipse:eclipse.
Info
titleUseful Information

Since the newer versions might give you some errors like: "Request to merge when 'filtering' is not identical.....", when you run mvn eclipse:eclipse.
Try using version 2.6, by running this command instead: mvn org.apache.maven.plugins:maven-eclipse-plugin:2.6:eclipse
or add this to your pom.xml:
<!-- prefent aspectj problems when running eclipse:eclipse -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.6</version>
<configuration>
<ajdtVersion>none</ajdtVersion>
</configuration>
</plugin>

  1. Launch Eclipse and go to File > Import > Existing Projects into Workspace (under the General category). Select the root directory of your project, followed by the modules to import. Click Finish to complete the process.

Set the classpath variable M2_REPO. Eclipse needs to know the path to the local maven repository. You should be able to do this by executing the command: mvn -Declipse.workspace=C:\Source eclipse:add-maven-repo.

If that doesn't work, can also define a new classpath variable inside Eclipse. From the menu bar, select Window > Preferences. Select the Java > Build Path > Classpath Variables page and set M2_REPO to equal ~/.m2/repository.

After configuring Eclipse, you should be able to compile your project and run tests from within your IDE. For tests that rely on pre-existing data, you may have to periodically run mvn dbunit:operation to re-populate your database. You shouldn't need to worry about deploying from Eclipse because you can use the Jetty Plugin (mvn jetty:run-war) or Cargo (mvn cargo:start -Dcargo.wait=true). If you'd prefer to use the Eclipse Web Tools Project to auto-deploy your project, see the Integration with WTP section below.

For more information on using Eclipse with Maven, see Maven's Eclipse Mini-Guide.

If you'd like to run Maven from Eclipse, see the Maven 2.x Eclipse Plugin.

Tip

The Eclipse project is likely to show multiple errors which are in fact not really errors. See APF-649

Info
titleUseful Information

If you've used the "mvn war:inplace" command, you'll likely have errors in Eclipse about conflicting libraries. These can be fixed by deleting the src/main/webapp/WEB-INF/lib directory.

rm -r src/main/webapp/WEB-INF/lib/

Integration with Eclipse Web Tools Project (WTP)
Anchor
wtp
wtp

See: Eclipse Web Tools Project

Below are some quick instructions contributed by Shash Chaterjee. For more information see this thread.

  1. Use the AppFuse archetypes to create the project. I used the Struts-2 Modular version. If you're not using a modular archetype, you can skip to step #6.
  2. Under "myproject", create a new dir called pom. Copy myproject/pom.xml to myproject/pom/pom.xml.
  3. Modify myproject/pom.xml to change the artifactId to "myproject-pom".
  4. Modify core/pom.xml and web/pom.xml to change the parent pom artifactId to
    "myproject-pom" and delete the relativePath element
  5. Modify myproject/pom.xml to add the "pom" module preceding to core and web in the modules section
  6. Modify myproject/pom/pom.xml to remove the "core" and "web" modules
  7. Run mvn install eclipse:eclipse
  8. Edit myproject/web/.settings/org.eclipse.wst.common.component:
    • Delete <wb-resource deploy-path="/" source-path="src/main/webapp"/>
    • Add <wb-resource deploy-path="/" source-path="target/myproject-webapp-1.0-SNAPSHOT"/>
    • Delete <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
    • Edit myproject/web/.classpath
    • Delete <classpathentry kind="src" path="src/main/resources" excluding="ApplicationResources_zh*.properties ... **/*.java"/>
    • Add <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5"/>
    • Add <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
  9. Preferences -> Java -> Installed JREs: Make sure default JRE is actually the JDK and not the JRE.
  10. Preferences -> Server -> Installed Runtimes: Pick an Apache -> Tomcat 5.5 server, and point it to your local installation.
  11. Import -> Existing Projects into Workspace: Point to your AppFuse project dir and import myproject-core and myproject-web.
  12. Open J2EE perspective, then Run->Run On Server (when prompted, connect it to the Tomcat server you configured previously)
  13. You may want to copy the launch configuration and then add all the properties defined in myproject/pom.xml.

Debugging
Anchor
debugging
debugging

One of the nice things about AppFuse 2.0 is you shouldn't have to use Maven for the most part. It has much better IDE support now. You should be able to run most of your tests from within Eclipse. If you can run your tests, you should be able to debug them as well. If you write your tests so they don't depend on data already being in the database, you should be able to run your tests all day long. If you depend on pre-existing data, you may have to run mvn dbunit:operation (same as ant db-load in AppFuse 1.x) every so often, or use DbUnit's Java API to pre-populate your database.

To debug your application while running it in Jetty , see Debugging with the Maven Jetty Plugin in Eclipse.

Spring Support
Anchor
spring
spring

Spring IDE is an excellent plugin to install for viewing, graphing and navigating Spring beans. Installing it should be fairly straight forward. Below is an example graph created with Spring IDE.

Wiki Markup
{div:style=text-align:center}!BeansGraph.png|thumbnail!{div}

Tips and Tricks
Anchor
tips
tips

  • Ctrl+Shift+R will allow you to find any file within your project. It's a handy way to open files quickly without having to navigate through your source tree.
    • Ctrl+Shift+T does the same, but restricted to Java source files (Java view only).
  • Ctrl+Shift+E opens a dialog with the files you most recently open listed.

In order to clean up the project view in Eclipse, you can hide the files you don't need. First of all, make sure you're in the Java Perspective (Window → Open Perspective). Then click the little (down) arrow in the top right corner of the Package Explorer pane. Select Filters and check Libraries from external and Libraries from project. Click OK to continue.

Another useful Eclipse trick is to use abbreviated package names. It's a nice feature on projects where you're inflicted with super.long.package.name.syndrome. Go to Window -> Preferences -> Java -> Appearance. Check the "Compress all package names" checkbox and type "1." (no quotes) in the text field.