95-702 Organizational Communications and Distributed Object Technologies August 2008 Installation Lab ================ This lab is not to be turned in but needs to be completed as soon as possible. PART I. Installation of Java 6, Tomcat 5.5, and Eclipse with Tomcat Plugin ========================================================================== 0. Please try to avoid directory paths using spaces. Use an underscore character instead. That is, use C:\My_Dir rather than C:\My Dir. 1. Make a directory for downloads. Call it c:\downloads. 2. Download the following files from www.andrew.cmu.edu/~mm6/95-702/downloads and place them in your c:\download directory: jdk-6u4-windows-i586-p.exe (JDK and JRE from Sun) apache-tomcat-5.5.17.exe (Apache Tomcat Install) eclipse-SDK-3.2-win32.zip (Eclipse IDE) tomcatPluginV31 (Eclipse plugin from Sysdeo) 3. Expand the Java to C:\Java. Within this directory you should have C:\Java\jdk1.6.0_04 and C:\Java\jre1.6.0_04 Double click and expand Tomcat. Select Full Install. Install to C:\Tomcat_5.5 (Note the use of underscore rather than space.) Upon running the Tomcat installation wizard: Set Username and Password and remember these. Set the port to 6502 (to stay away from Oracle's Tomcat). Select the installed JRE that is under the new JDK that we just installed. Don't use any other JRE. The last token in the path should be "jre". Within the C:\Tomcat_5.5 directory you should have C:\Tomcat_5.5\bin, C:\Tomcat_5.5\common, etc. Expand eclipse to C:\eclipse Within this directory you should have C:\eclipse\eclipse.exe, etc. Expand plugin to C:\EclipseTomcatPlugin Within this directory you should have C:\EclipseTomcatPlugin\..\com.sysdeo.eclipse.tomcat_3.1.0 Copy the entire directory com.sysdeo.eclipse.tomcat_3.1.0 to C:\eclipse\plugins. This allows us to access Tomcat from within Eclipse. 4. Use Start/Control Panel/Performance and Maintenance/System/ Advanced/Environment Variables/System Variables/New to set the following: JAVA_HOME C:\Java\jdk1.6.0_04 JRE_HOME C:\Java\jdk1.6.0_04\jre Path C:\Java\jdk1.5.0_08\jre\bin;C:\Java\jdk1.6.0_04\bin;{everything already there follows here} 5. Make a shortcut to eclipse and place it on your desktop. Right click on shortcut properties and set target to C:\eclipse\eclipse.exe -vm C:\Java\jdk1.6.0_04\jre\bin\javaw Note that we are pointing to the JDK we just installed. 6. Testing from the DOS prompt: C:\>java -version java version "1.6.0_04" C:\>javac -version javac 1.6.0_04 C:\>echo %JAVA_HOME% C:\Java\jdk1.6.0_04 C:\>echo %JRE_HOME% C:\Java\jdk1.6.0_04\jre 7. Double click eclipse. Choose a workspace like C:\97-702\EclipseWorkSpace1. The following Tomcat setting that we will make apply to this eclipse workspace. These setting will still be there the next time you choose this workspace. Choose workbench. Select Windows/Preferences/Tomcat and select * Version 5.0 and set Tomcat home to C:\Tomcat_5.5 Select Windows/Preferences/Tomcat/Advanced and set Tomcat Base to C:\Tomcat_5.5 Select Windows/Preferences/Tomcat/Tomcat Manager and set your user name and password. These are the same names that you entered earlier when you installed Tomcat. Apply the changes and click the little cat (Start Tomcat). If you throw exceptions try stopping Tomcat and starting it again. If you can't get Tomcat to run see your TA or instructor ASAP. 8. Visit Tomcat with your browser at http://localhost:6502 Run the servlets and JSP's under Examples. These should all work. Select Tomcat Manager and see if your user name and password work. Go back to eclipse and click the little cat to stop Tomcat. Exit eclipse. 9. Publish a Java Server Page (JSP). Double click eclipse. Choose the same workspace like C:\97-702\EclipseWorkSpace1. Choose workbench. Examine Windows/Preferences/Tomcat and see if your old settings are still there. Choose File/New/Other/Java/Tomcat Project/Next Project Name Cool-JSP-project Finish On the left pane (Package Explorer) expand the Cool-JSP-project (it should contain WEB-INF as well as a host of Java Archives (jar files)) On the left pane select Cool-jsp-project and Right Click and select new file. Enter the file name MyCoolPage.jsp and click finish. You should see this file under but not in the WEB-INF directory. Enter this document in the editor: <% java.util.Date d = new java.util.Date(); %> Today is <%= d.toString() %> Click the little disk to save everything. Start Tomcat with the little cat. Use a browser to visit http://localhost:6502/Cool-JSP-project/MyCoolPage.jsp 10. Another tutorial covering this same topic is at http://www-128.ibm.com/developerworks/library/os-ectom/ 11. Publish a servlet. Choose File/New/Other/Java/Tomcat Project/Next. Project Name ANewApp-project Finish On left pane expand the ANewApp-project project (it should contain WEB-INF) On left pane select ANewApp-project and Right Click and select new file. Select ANewApp-project and enter the file name index.jsp and click Finish. Enter this document in the editor: Introductions
Please enter name

Click the little disk to save everything. Select ANewApp-project and right click Select new/class and give it the name HandleForm (we will use the default package). Click Finish. Enter this java servlet in the editor for HandleForm.java. // HandleForm.java // An introductory servlet import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HandleForm extends HttpServlet{ public void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { String personName = req.getParameter("personName"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String docType = "\n"; out.println(docType + "\n" + "Hi" + personName + "\n" + "\n" + "

Hi"+ personName + "

\n" + ""); } } In the left pane, select the WEB-INF folder. This is NOT the WEB-INF/src folder. Right click WEB-INF and select new file. Enter file name web.xml and Finish. Enter this web.xml file. This file associates the name ProcessForm with the servlet HandleForm. TestServlet HandleForm TestServlet /ProcessForm/* Stop Tomcat and then start Tomcat again. Use a browser to visit http://localhost:6502/ANewApp-project/index.jsp Enter your name and hit submit. The servlet should execute.