Using Eclipse Projects

Dealing with the zipped projects bundled with the tutorials on beginning & intermediate servlets & JSP, advanced servlets & JSP, Ajax, GWT, Spring, Hibernate & JPA, JSF 1.x, JSF 2.0, EJB3, Web services, and Java 6 programming.


The code in these tutorials was created with the Eclipse IDE. I use version 3.6 (Helios) with Java 6, but virtually all the examples should run fine in Eclipse 3.5 (Galileo), and many of them should work with Java 5. If you don't already know how to use Eclipse, information on downloading Eclipse and configuring it to be used with Tomcat can be found at the Tomcat and Eclipse tutorial. Although Eclipse or another IDE (NetBeans, MyEclipse, IntelliJ IDEA, etc.) is strongly recommended for Java EE development, none of the coreservlets code is in any way specific to Eclipse.

Importing Zipped Eclipse Projects into Eclipse

To import the zipped projects that are bundled with the tutorials, follow these steps:

  1. Download the .zip file.
  2. Open Eclipse. The projects were created in Eclipse, but the pieces can easily be copied to projects in NetBeans, MyEclipse, or IDEA.
  3. Go the the File menu and select "Import".
  4. Choose "Existing Projects into Workspace". Do not choose "Archive File" directly from "Import". Press the "Next" button.
  5. Choose the second radio button that says "Select archive file". Press the "Browse" button and navigate to the .zip file you downloaded in Step 1. Press "Next" and follow the directions from there.
  6. Most of the servlet/JSP, Ajax, JSF, Spring, Hibernate, EJB3, GWT, and Web Service projects assume that you already have Tomcat or another server configured for use in Eclipse. If you don't have this set up already, see the Tomcat and Eclipse tutorial.

Importing Zipped Eclipse Projects into NetBeans

NetBeans claims to be able to reliably import Eclipse projects. For details, please see

Deploying and Testing Apps Locally

This section applies only if you are importing an Eclipse Web project. Skip this section if you are importing ordinary Java projects (e.g., from the Java 6 programming tutorial).

First, make sure that you have Tomcat installed on your local computer, and that Eclipse knows about Tomcat. If you haven't done this already, see the Tomcat with Eclipse tutorial.

Once you have Tomcat set up with Eclipse and you have imported a Web project, deploy the app as follows: Click on Servers tab at bottom. R-click on Tomcat v7.0 Server, choose "Add and Remove Projects". Then choose your app. Start Tomcat, or restart it if already running (R-click on Tomcat and choose either "Start" or "Restart"). Open a browser and try http://localhost/your-app-name/some-url-in-your-app. For example, if your app is named "myApp" and it has index.html and test1.jsp files in the WebContent folder, use the URLs http://localhost/myApp/ and http://localhost/myApp/test1.jsp.

The Art of WAR:
Making WAR Files for Deployment on Production Server

Again, this section applies only if you are importing an Eclipse Web project. Skip this section if you are importing ordinary Java projects (e.g., from the Java 6 programming tutorial).

To test on your local Tomcat server, you do not need to make a WAR file. Just follow the deployment instructions above. When you are learning and practicing, that is enough. However, in a work setting, you will eventually deploy to a production server, and you will want a WAR file for that. To make a WAR file, R-click on the project in Eclipse, then choose Export and WAR file (or, in some Eclipse environments, Export, Web, WAR file). Click Browse to pick a location to save the WAR file. You can now upload that WAR file to the deployment folder of any Java-capable server that supports the same (or later) servlet/JSP version that you used for development.

Changing Zipped Eclipse Projects into
Normal (Deployable) Web Applications

Again, this section applies only if you are importing an Eclipse Web project. Skip this section if you are importing ordinary Java projects (e.g., from the Java 6 programming tutorial).

Please note that you do not have to do this if you have Eclipse or another IDE! Your IDE will handle local deployment and building of WAR files automatically. These steps are only for users that are not using an IDE. Use of an IDE is very strongly recommended: the time to download Eclipse, set it up with Tomcat, and learn the most basic uses will be repaid very quickly. See the Tomcat and Eclipse tutorial. But, if you really need to import the coreservlets samples into an environment that has no IDE, read on.

Eclipse projects create two extra directories at the top-level of the project: src and WebContent. To make a regular Web application, you have to move the files under src to WebContent/WEB-INF/classes, then rename WebContent to your Web app name. For example, to turn the Eclipse project into a normal Web app, follow these steps:

  1. Extract everything from the .zip file, resulting in a folder called facelets.
  2. Go to facelets/src and copy all folders and files.
  3. Go to facelets/WebContent/WEB-INF/classes, and paste everything copied from Step 2.
  4. Rename WebContent to facelets and move that new facelets folder to whatever location you store Web apps.
  5. Again, these steps are not needed if you use Eclipse, NetBeans, MyEclipse, IntelliJ IDEA, or another IDE. Those IDEs will handle deployment for you.

More Information


JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA