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:

File:EclipseWebToNetBeans/01-newweb-eclipse EclipseWebToNetBeans.jpg

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

File:EclipseWebToNetBeans/03-newweb-eclipse-2 EclipseWebToNetBeans.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:

File:EclipseWebToNetBeans/02-newweb-eclipse-appsrv-1 EclipseWebToNetBeans.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:

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

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

File:EclipseWebToNetBeans/04-webproject-empty EclipseWebToNetBeans.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":

File:EclipseWebToNetBeans/05-jsp EclipseWebToNetBeans.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):

File:EclipseWebToNetBeans/06-jsp-edit EclipseWebToNetBeans.jpg

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

File:EclipseWebToNetBeans/07-servlet EclipseWebToNetBeans.jpg

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

File:EclipseWebToNetBeans/08-servlet-edit EclipseWebToNetBeans.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"...,

File:EclipseWebToNetBeans/09-runonserver EclipseWebToNetBeans.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
and/or handled the welcome page call in another meaningful way. However by now we should be capable of both running our JSP file...

File:EclipseWebToNetBeans/10-run-jsp EclipseWebToNetBeans.jpg

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

File:EclipseWebToNetBeans/11-run-servlet EclipseWebToNetBeans.jpg

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

File:EclipseWebToNetBeans/12-tomcat-stop EclipseWebToNetBeans.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:

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

... select the right project:

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

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

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

Eclipse project imported to NetBeans will look like this:

File:EclipseWebToNetBeans/15-nb-afterimport EclipseWebToNetBeans.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)

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