|
APACHE TOMCAT
6
APACHE TOMCAT 7 JAVASERVER FACES (JSF) JSF 1.x JSF 2.0 INTERMEDIATE SERVLETS & JSP ANDROID PROGRAMMING AJAX & GWT JAVASCRIPT & AJAX BASICS PROTOTYPE SCRIPTACULOUS JQUERY DOJO GWT 2.1 JAVA 6 & 7 PROGRAMMING HTML 5 ADVANCED SERVLETS & JSP SPRING HIBERNATE & JPA JAKARTA STRUTS EJB3 WEB SERVICES WITH AXIS2 SCWCD TUTORIALS IN CHINESE TUTORIALS IN JAPANESE
ABOUT THE INSTRUCTOR COURSE REVIEWS JSF 2.0, MYFACES, & PRIMEFACES AJAX (w/ JQUERY, HTML5, ETC.) JAVA 6 & 7 PROGRAMMING ANDROID PROGRAMMING GWT INTERMEDIATE SERVLETS & JSP SPRING FRAMEWORK HIBERNATE & JPA ADVANCED SERVLETS & JSP JAKARTA STRUTS 1.x & STRUTS 2 SCWCD IPHONE PROGRAMMING CUSTOMIZED ON-SITE PUBLIC TRAINING SCHEDULE
|
Tutorial: Installing Tomcat 7 and Using it with EclipseThis tutorial covers Tomcat 7, which supports the servlet 3.0 and JSP 2.2 specs. For coverage of Tomcat 6 (servlets 2.5, JSP 2.1), please see the tutorial on Eclipse with Tomcat 6. It takes only a short time to download Eclipse and learn the bare bones basics of using it to build Web apps and deploy them to Tomcat, and all the information you need to do this is described in this tutorial. This time will be very quickly recouped by the savings in development, debugging, and deployment times. To get started with web apps in Eclipse, you only need to know a very small number of features. You can gradually learn the advanced capabilities at your leisure. Also note that if you print this page, the entire contents (including the expanded contents of all the accordion tabs below) will be printed. If you find these free tutorials helpful, we would appreciate it if you would link to us. Send corrections or feedback on any tutorial to hall@coreservlets.com. Executive SummaryHere is a quick summary of basic use; see the next sections for details.
Install JavaDownload from http://www.oracle.com/technetwork/java/javase/downloads/. Get the standard edition (Java SE), not the enterprise edition (Java EE). Be sure to get the JDK (which has a compiler), not just the JRE (which is for running preexisting applications). I use JDK 1.6.0_22, but any Java 6 version will work. Servlet 3.0 containers (of which Tomcat 7 is one) require Java 6, and will not work with Java 5. Once you have downloaded the installer, run it and accept all default settings. There is no need to set any environment variables, but if you already had an earlier version of Java installed and you had set the PATH variable (pointing at the bin subfolder) or the JAVA_HOME variable (pointing at the main installation folder), it is a good idea to update them to the new version. Also, please note that if you use 1.6.0_21, you also need to fix the Eclipse PermGen space error or Eclipse will run out of memory and crash. That is the only Java version where you have this problem. Unzip TomcatUnzip tomcat-7.0.8-preconfigured.zip into the location of your choice. I use the top level of the C drive, resulting in C:\apache-tomcat-7.0.8\. This preconfigured version of Tomcat has the following settings already in place.
Alternatively, you can download any Tomcat 7 version from the Tomcat Web site and then copy context.xml, server.xml, and web.xml into install_dir/conf. These files are annotated with comments on what modifications were done to them. Install and Start Eclipse
Go to http://www.eclipse.org/downloads/. Choose "Eclipse IDE for Java EE Developers", download, and unzip. Only the latest version, Eclipse 3.6 (Helios), comes with an adapter for Tomcat 7. There is no real installer, so unzipping it is all you need to do. I normally unzip into the top level of the C drive, resulting in C:\eclipse, but any location is fine.
After you start Eclipse, select "Workbench" as shown on the image to the right. Tell Eclipse about Tomcat
First, start Eclipse and go to the Workbench as shown in the previous section.
Then, click on Servers tab at bottom. (If you don't see Servers tab,
add the tab via Window, Show View, Servers.) R-click on Servers tab, New,
Server, Apache, Tomcat v7.0, navigate to folder, OK. You should now
see "Tomcat v7.0 Server at localhost" listed under the Servers tab at the bottom. Run Tomcat
If you fail to copy the ROOT files as mentioned below, http://localhost/ will result in a 404 error. But, the error page comes from Tomcat, so it shows that Tomcat is running. The problem is that Eclipse doesn't copy the default Web application to the Eclipse/Tomcat folder. However, if you copy the ROOT files as described in the next section, http://localhost/ will give the nice friendly "Welcome to Tomcat" page. If you get a "port 80 is already in use" message, that means you have another server already using port 80 (probably IIS). To stop the other server, go to the Control Panel, Services, and stop it from there. Or, double click on Tomcat at the bottom of the Eclipse window and change the HTTP/1.1 port (see the upper right) from 80 to something else. But using port 80 is nicer, so it is better to stop the other server instead of changing the Tomcat port. It is also easy to start and stop Tomcat manually, without using Eclipse. Just go to the "bin" folder of the Tomcat installation directory (e.g., C:\apache-tomcat-7.0.8\bin) and double click on startup.bat and shutdown.bat. You can also manually deploy WAR files to the "webapps" folder of the Tomcat installation directory. However, doing everything in Eclipse is much more convenient because Eclipse automatically sends over changes as you modify files. Copy the ROOT (Default) Web App into Eclipse.Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace. Go to C:\apache-tomcat-7.0.8\webapps, R-click on the ROOT folder and copy it. Then go to your Eclipse workspace, go to the .metadata folder, and search for "wtpwebapps". You should find something like your-eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or .../tmp1/wtpwebapps if you already had another server registered in Eclipse). Go to the wtpwebapps folder, R-click, and paste ROOT (say "yes" if asked if you want to merge/replace folders/files). Then reload http://localhost/ to see the Tomcat welcome page. Import and Test a Sample App
Grab test-app.zip and save it. Import it into Eclipse with File, Import, General, Existing Projects, Select archive file. Then click Browse and navigate to test-app.zip. Note that this app uses the @WebServlet annotation to give URL patterns to servlets, and will only run in Tomcat 7 or other servlet 3.0 containers. It will not run in Tomcat 6. Click on Servers tab at bottom. R-click on Tomcat v7.0 Server, choose "Add and Remove Projects". Choose test-app. Start Tomcat, or restart it if already running (R-click on Tomcat and choose either "Start" or "Restart"). Try the following URLs in a browser:
Create a New Web App in Eclipse
Add Code to New Apps in EclipseHere is a quick summary of the most commonly used folders in Dynamic Web Projects in Eclipse.
Test New Apps in EclipseFollow same procedure as given in example above with "test-app" app: Click on Servers tab at bottom. R-click on Tomcat v7.0 Server, choose "Add and Remove Projects". Choose app. Start Tomcat, or restart if already running. Open http://localhost/appName/ in browser. You must restart the server after adding a new project. To do so, R-click server and choose "Restart". For details on writing servlets, giving them custom URLs, using JSP, applying the MVC architecture, creating JSP custom tag libraries, and many other servlet and JSP topics, please see the servlet and JSP programming tutorial. Adjust Eclipse Preferences
One customization you almost always want to do is to suppress the unneeded warning re serialVersionUID on Serializable classes. The HttpServlet class is already Serializable, but nobody actually sends instances across the network or writes them to disk, and certainly almost nobody puts in a serialVersionUID field in servlets. But, if Eclipse marks every servlet with a warning, you get in the very bad habit of ignoring warnings. Most of the warnings are actually useful; this is a rare exception. So, go to Window, Preferences, Java, Compiler, Errors/Warnings, expand "Potential programming problems", and change "Serializable class without serialVersionUID" to "Ignore". Also, if you were already using Eclipse with an earlier Java version, go to Window, Preferences, Java, Installed JREs, and make sure the new Java version is selected. Access the Servlet and JSP JavadocsThe single most useful reference for a servlet and JSP developer is the online API. Sadly, as of October 2010, there was no online version of the servlet 3.0 and JSP 2.2 Javadocs, and browsing the massive Java EE 6 API is much more difficult because the servlet and JSP classes get lost in the crowd. So, I generated the API from the Tomcat 7 source code. You can access the result at http://docs.coreservlets.com/servlet-3.0-api/. And, if you haven't already done so long ago, bookmark the Java SE 6 API. More Information
|
announcements
Too few developers for
Android Programming: August 13-17 2012
JSF 2.0 & PrimeFaces: August 20-24 2012
Java 7 Programming: August 27-31 2012
Rich Internet Apps September 10-14 2012
Spring: Simplifying September 17-21 2012
Java Persistence with April 11-15 2011
RESTful & SOAP-based October 29-31 2012 Courses at CEU's Now Available
|
||||||||||||||||
| © 2012 coreservlets.com | Original design by TBIQ | Hosting from Kattare | ||||||||||||||||||



Start Eclipse by going to the "bin" folder and double-clicking on eclipse.exe. I usually make a shortcut on the desktop by
R-clicking on eclipse.exe, selecting Copy, then going to the desktop, R-clicking, and doing Paste Shortcut.
Click on Servers tab at bottom. R-click on Tomcat v7.0, choose
"Start". Open http://localhost/ in a browser: you will see a 404 error message, but at least the message
comes from Tomcat. Then, copy the ROOT app as described in the next section, come back,
and reload http://localhost/. You should now see the normal Tomcat welcome page.


There are many customizations you can do in Eclipse. You can adjust the font size, colors,
indentation styles, import statement formats, and much much more. Go to Window, Preferences and browse around.