Monday, April 25, 2011

Setting up Eclipse for developing web based applications using SVN, Maven and Tomcat.

1. Download "Eclipse IDE for Java EE Developers" from http://www.eclipse.org/downloads/

2. Add subversive:

• On main menu, choose Help > Install New Software. The available Software dialog appears.
• In the Work with list, select Helios - http://download.eclipse.org/releases/helios. A list of software packages appears.
• Expand the Collaboration node.
• Scroll the list and check box for Subversive Team Provider (incubation)
• Check other options in the dialog as desired and click the Next button. The Install Details screen appears in the dialog.
• Click the Next button, accept the license and click Finish. Subversive will download and install.
• It is recommended to accept the option to restart Eclipse.

Once Eclipse is restarted, try to import from SVN. "Subversive Connector Discovery" window will pop up.
Select "SVN Kit 1.3.5" or the latest number. Select Next and accept user agreement.

At this point, the trick is to abort the import process and restart eclipse. You should be able ti import again.

To list the installed plugin: Help>Install New Software, and selected "already installed?"

Eclipse IDE for Java Developers 1.3.2.20110218-0812 epp.package.java
Subversive SVN Connectors 2.2.2.I20110124-1700 org.polarion.eclipse.team.svn.connector.feature.group
Subversive SVN Team Provider (Incubation) 0.7.9.I20110207-1700 org.eclipse.team.svn.feature.group
SVNKit 1.3.5 Implementation (Optional) 2.2.2.I20110124-1700 org.polarion.eclipse.team.svn.connector.svnkit16.feature.group

3. Add m2eclipse

• On main menu, choose Help > Install New Software. The available Software dialog appears.
• In the Work with list, add http://m2eclipse.sonatype.org/sites/m2e
• Select Maven Integration for Eclipse and accept license agreement.
• Maven Maven will download and install. Restart Eclipse.

To list the installed plugin: Help>Install New Software, and selected "already installed?"

Eclipse IDE for Java Developers 1.3.2.20110218-0812 epp.package.java
Maven Integration for Eclipse (Required) 0.12.1.20110112-1712 org.maven.ide.eclipse.feature.feature.group
Subversive SVN Connectors 2.2.2.I20110124-1700 org.polarion.eclipse.team.svn.connector.feature.group
Subversive SVN Team Provider (Incubation) 0.7.9.I20110207-1700 org.eclipse.team.svn.feature.group
SVNKit 1.3.5 Implementation (Optional) 2.2.2.I20110124-1700 org.polarion.eclipse.team.svn.connector.svnkit16.feature.group

4. Download "Tomcat 7" from http://tomcat.apache.org/download-70.cgi

5. In Eclipse, Select Window>Show View>Servers. This will add a new tab to the bottom window. Select "Servers" tab and right click to select New>Server. Select Apache>Tomcat v7.0 Server and provide the required information such as the directory where you installed Tomcat, etc.

At this point, you should be ready to create a new "Dynamic Web Project" that can be added to your Tomcat server or import an existing Maven project from a SVN repository. In order to run an imported Maven project on Tomcat you need to issue the following command from a shell:

mvn eclipse:eclipse -Dwtpversion=1.5

The trick is to go back to eclipse and change the following Project properties:
Java Compiler : Make sure Java version is set to 1.6 or higher
Project Facets : Select Dynamic Web Module to use the appropriate Java version.

Tips

1. If you get a "java.lang.OutOfMemoryError: PermGen space" when running Tomcat in Eclipse, edit eclipse.ini to modify your JVM settings.

On MacOS, you can find eclipse.ini in ~eclipse/Eclipse.app/Contents/MacOS.
Your settings should look something like, making sure each item is on a new line:
-vmargs
-Xms128m
-Xmx512m
-XX:MaxPermSize=512m

To verify your settings in Eclipse, Select About Eclipse>Installation Details>Configuration.

2. You may get a "ClassNotFoundException" when running your web app on a Tomcat server. The exception is in reference to a class in a jar file that is already added as a Maven dependency and exists in target//WEB-INF/lib, however Tomcat still throws the exception when running.

Here is the solution:

Check your "Problems" tab for warnings such as:

"Classpath entry org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER will not be exported or published. Runtime ClassNotFoundExceptions may result. "

You can achieve the same by selecting your project's properties->Deployment Assembly->Add->Java Build Path Entries.

Select the row corresponding to your project and perform a "Quick Fix" by right clicking it. Select "Mark the associated raw classpath entry as a publish/export dependencies."