SharingProjectNetBeansEclipse

Sharing a Spring-based project between NetBeans and Eclipse

This demo script is part of the NetBeans World Tour 2008 session #2, Using NetBeans For Your Existing Projects.

Main Points to Hit

  • It is possible to share projects between NetBeans and Eclipse
  • There is a Spring plugin for NetBeans
  • The IDEs are similar, although we consider NetBeans as more intuitive and less annoying

Prerequisities

  • JDK5 or JDK6
  • NetBeans 6.0 M10 or higher (because of the Spring plugin)

Setup

  1. Install Eclipse Europa for Java EE developers from eclipse.org
  2. Install AspectJ Development Tools - Help > Software Updates > Find and Install > Search for new features to install > Europa Discovery Site > Finish. Then Europe Discovery Site > Java Development > AspectJ Development Tools (AJDT)
  3. Install the Spring IDE by updating Eclipse using the following update center (Help | Software Updates | Find and install): http://springide.org/updatesite/site.xml
  4. Configure Eclipse to use the JDK instead of JRE using Window | Preferences | Java | Installed JREs. Otherwise the Spring example wouldn't work. Get rid of the JRE, just replace it with JDK.
  5. Since Eclipse comes with no application server, set up NetBeans' Tomcat in Eclipse :). Switch to the Java EE perspective and add it via the Servers tab.
  6. Download the Spring framework (the stable version, with dependencies) from springframework.org and unzip it.
  7. Navigate to the ${spring.root}/samples/countries/war/WEB-INF directory and create a lib directory
  8. Navigate to the ${spring.root}/lib directory and copy the following jars into the {{${spring.root}/samples/countries/war/WEB-INF/lib directory you just created:
  • dist/spring.jar
  • jakarta-commons/commons-logging.jar
  • lib/jakarta-taglibs/standard.jar
  • j2ee/jstl.jar
  • itext/*.jar
  • poi/*jar
  1. Install the NetBeans Spring module from http://spring-netbeans.sourceforge.net

Gotchas

Come on, it's Eclipse!

Demo Steps

In this demo we're going to use the Spring Countries sample application that ships with the Spring framework to demonstrate how easy it is for Eclipse and NetBeans to work side-by-side.

Configure the Project for Eclipse

  1. Start Eclipse. NetBeans should be already running from your previous demos.
  2. Create a new Dynamic Web Project (File > New > Project > Web). Mention you don't understand why Eclipse has a "static" and "dynamic" web project :).
  • Project name: countries.
  • Uncheck Use default and set the Project contents Directory to: ${spring.root}/samples/countries/
  • Target Runtime: Apache Tomcat v6.0
  • Click Next and Next to get to the Web Content page
  • Set the Content Directory to war, which matches the sample application's content directory. (Note, NetBeans automatically detects the proper content directory name.)
  • Uncheck Generate Deployment Descriptor. This is important as the sample application already has one and we dont' want to overwrite it.
  • Click Finish
  • Verify that Eclipse detected the libraries (countries > Libraries > Web App Libraries)
  1. Right-click the project and choose Run As > Run On server. Choose Tomcat as default and check the checkbox to always use Tomcat as a server for this project. In next section leave the countries as configured for this server. Click Finish. Confirm stupid dialog about syncing web.xml, you'll see it more often since now.
  2. The sample project should be up & running. If not, try to investigate the error and maybe someone from the audience can help you :)
  3. Go to Main in the web application and show the list of countries. Click on PDF to generate PDF and Excel to generate Excel sheet.
  4. Customize the project a bit. Open messages.properties and change the app.short name to Eclipse Rules!

Configure the Project for NetBeans

  1. Create a new Web Application with existing sources.
  • Point the wizard to ${spring.root}/samples/countries/.
  • The wizard will complain that there is already a build directory in the application. Eclipse doesn't appear to have a pure clean option - the Eclipse Clean also rebuilds the project. Also, trying to delete the build directory from Eclipse only deletes the classes, not the actually build directory. So...go to the file manager and delete the build directory. In the case where the project was checked out from a source repository, the build directory would not be there to begin with.
  • Return to the NetBeans New Web Project with Existing Sources wizard. Click Back and Next to refresh the page. All should be fine now.
  • Choose Tomcat as server and click Next.
  • NetBeans detects the existing build.xml and offers an alternative name, nbbuild.xml. Select OK to accept.
  • On the Existing Sources and Libraries page, note NetBeans detected all of the relevant folders (in Eclipse we had to replace "WebContent" with "war")
  • Click Finish.
  1. Run the project. Tomcat will be started and application should run. No annoying messages this time :) Do the same demo as when the application was running from Eclipse to show that PDF and XLS integration works. The migration to NetBeans was painless this time, but mention that this might not be the case if the application would have a non-standard project structure or use custom build scripts. Then free-form project might wokr better.
  2. Show the HTTP monitor and explain it's usage. Mention that this is a great feature in NetBeans for monitoring requests and responses.
  3. Expand all nodes in the project to show the project structure in NetBeans.
  4. Show the project directory in file manager. Explain that .classpath and .project files are from Eclipse. build.xml and nbproject are from NetBeans. These files can coexist in one project directory.

Project Sharing

We're not too happy with our teammates new application name.

  1. Open messages.properties in NetBeans and change the app.short property to NetBeans Rocks!
  2. Run the project to see the results. Alternatively you can set reloadable="true" in context.xml (see Why not set reloadable="true" ?) and just refresh the browser.
  3. Switch to back to Eclipse. Eclipse will detect that message properties has been changed and prompt you to reload the file. Decide you're cool with this new application name :-).
  4. Select Project > Clean to rebuild the project.
  5. Run the project to see the results (note, the projects are deployed to 2 different server instances - I don't know if there's a way to get them to share the same instance -- see issue 114820).

Did You Know?

  1. Show the Eclipse keybindings settings and emacs keybindings. Mention we have a vi plug-in as well.
  2. Talk about how NetBeans detected that Eclipse was running Tomcat on port 8080 and thus started a new instance on port 8084 (yes, but is there any way to get NetBeans to share the instance with Eclipse?)
  3. Ask the audience if they have any questions about NetBeans & Eclipse running together.

Spring Module Features

Show basic features of the Spring module:

  1. Go to the project properties and frameworks. Show that Spring 2.0 was added as framework.
  2. Open Configuration Files | Application Context. Type a new <bean and show code completion. Delete the addition.
  3. Mention that there are other features available, but we don't have time to show them, so developers should check them out on the spring module project page. Mention this is a community-developed project and already reached version 1.0, found at http://spring-netbeans.sourceforge.net.

Free-form Project Demo

The point of this demo is to show the additional complexity imposed by choosing to use free-form projects.

  1. Delete the countries project, but leave the sources
  2. Create a new project using existing Ant script (free-form)
  3. Show how the targets need to be mapped, and that no targets currently exist for deploy. These tasks were taken care of using the regular project type but need to be defined using the free-form project type.

Demo Cleanup

  • Undeploy the countries project from Tomcat.
  • In Eclipse, right-click the countries project and select Delete.
  • Delete the the ${spring.root}/samples/countries/.project file, otherwise, Eclipse will not let you create a project against this directory again (the Delete project option only deletes the project from the workspace - not the project settings).
  • Delete the nb-build.xml and nbproject directory If you use NetBeans' Delete Project option, it deletes the WEB-INF/lib directory, so you'll have to set that up again.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo