[RSS]

Import an Eclipse WTP project into NetBeans 6.5

(0) Preface

Tested with latest builds of NetBeans 6.5, Eclipse Europa (3.3.1) and Ganymede (3.4), Apache Tomcat 6.0.14, using JDK 1.6.0_03 on Ubuntu GNU/Linux 7.10. NetBeans is supposed to be installed using the bundled Tomcat 6.0.14 container.

(1) Creating and testing an Eclipse Web project

Once in your Eclipse workspace, use the "New" -> "Project" wizard to create a "Dynamic Web Project" like this:

EclipseWebToNetBeans/01-newweb-eclipse.jpg

In our example, this project will be named foobar as the name obviously doesn't matter:

EclipseWebToNetBeans/03-newweb-eclipse-2.jpg

In most cases (if you do have a running web dev workspace), you are likely to have a servlet container / application server configuration already around and working, otherwise please click the "New" button right of "Target Runtime" combo box and follow the next steps to add a new Apache Tomcat runtime configuration:

EclipseWebToNetBeans/02-newweb-eclipse-appsrv-1.jpg

By then, browse to the folder of your local Tomcat installation (CATALINA_HOME, if you're familiar with running Tomcat from the shell) and finish creating your server runtime as well as creating your project:

EclipseWebToNetBeans/02-newweb-eclipse-appsrv-2.jpg

By then, you should see an empty Eclipse WTP project structure looking more or less like that:

EclipseWebToNetBeans/04-webproject-empty.jpg

To do our demonstration, we want to add an empty JSP as well as an empty servlet and make them generate some (pointless yet working) output. First, the JSP: Right-click the "foobar" project in your workspace, choose "New" and then "JSP":

EclipseWebToNetBeans/05-jsp.jpg

The file will be located in the WebContent folder of your project and be named "foo.jsp", for the sake of consistency. By then, you'll see that Eclipse has already opened the newly created file in an editor for you to insert something meaningful (like the "h1" statement shown in the image):

EclipseWebToNetBeans/06-jsp-edit.jpg

Next, the servlet. Again, right-click the project and choose "New" -> "Servlet", to create an EmptyServlet class in the foobar package:

EclipseWebToNetBeans/07-servlet.jpg

Again, you're provided with an editor to actually put code to the servlet, please modify the doGet(...) method as outlined in the next picture:

EclipseWebToNetBeans/08-servlet-edit.jpg

By now, we're ready to test-drive this (rather simple) application on our local Tomcat server. For that, again right-click the project, choose "Run" -> "Run on server"...,

EclipseWebToNetBeans/09-runonserver.jpg

... keep all settings at the default and proceed clicking "Finish". By then, a browser window will open inside the Eclipse workspace showing an error (which is because we haven't set an index.jsp and/or handled the welcome page call in another meaningful way. However by now we should be capable of both running our JSP file...

EclipseWebToNetBeans/10-run-jsp.jpg

... and our servlet file by using the appropriate URL mappings in the browser window:

EclipseWebToNetBeans/11-run-servlet.jpg

So far, so good. Now let's stop Tomcat using the "Big Red Button" in the lower right of your workspace...

EclipseWebToNetBeans/12-tomcat-stop.jpg

and move forth.

(2) Importing to NetBeans 6.5

Start with importing Eclipse project to NetBeans via "File" -> "Import Project" -> "Eclipse Project", choose the Eclipse workspace to contain your 'foobar' project:

EclipseWebToNetBeans/13-nb-eclipse-import-1.png

... select the right project:

EclipseWebToNetBeans/14-nb-eclipse-import-2.png

... select application server to use and press Finish to start import:

EclipseWebToNetBeans/14-nb-eclipse-import-3.png

Eclipse project imported to NetBeans will look like this:

EclipseWebToNetBeans/15-nb-afterimport.png

Press F6 (or via menu Run -> Run Project) and you get the same result as when executed from Eclipse. (Note: before running project from NetBeans you may want to stop Tomcat server in Eclipse otherwise you will get an error that port is already in use)