COMS 4111 - Instructions for Java & JDBC on Mac:
STEP 1:
Download
Apache Tomcat from here: http://apache.osuosl.org/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36.tar.gz
Unzip the Apache package to a directory (eg. /Applications/)
STEP 2:
Create
a new "Dynamic Web Project" in Eclipse. (You can download Eclipse from
http://www.eclipse.org/downloads/
if you don’t have it.)
STEP 3:
Under Target Runtime, you see <None>, because you haven't created a runtime yet for Apache Tomcat. Click New to open the New Target Runtime Wizard. Select Apache Tomcat V6.0 from the Apache folder, then click Next.
Click Browse to locate the base folder for your Apache Tomcat configuration. Once you've entered a valid directory, click Finish to create the runtime configuration.
STEP 4:
Go
to Windows menu, then Show View and then Servers.
In the Servers view, double click the server you created. Then a window opens, and you should edit the port number of Tomcat.
Change the port numbers: 8005 -> 9005, 8080 -> 9080 & 8009 -> 9009.
STEP 5:
To connect to the Oracle server, download ojdbc6_g.jar (if JRE 6.0 or JDK 1.6 is being used) from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_111060.html
You can download and install the newest JDBC driver. A free account with Oracle will be needed to download this file. After downloading the JDBC driver file, we store it under “WebContent/WEBCINF/lib”. (You can use drag and drop.)
STEP 6:
The easiest way to test your new dynamic Web project and Tomcat server integration is to create a simple JSP and deploy it to Tomcat. You can create the new JSP file by selecting File > New > Other, or you can use the context sensitive menu by right clicking the project name in the Project Explorer view and selecting New > JSP.
Make sure the parent folder is WebContent and name the file oracle_sample.jsp. Click Finish to create the page using the default template. If you click Next, you can choose different templates to use (such as HTML or XHTML) for the new page. The defaults are fine for this test. Following is “oracle_sample.jsp”.
Note: Here you need to use “ADB” for the connection string for both servers, even if you want to connect to w4111b.cs.columbia.edu. In this example, “scott” is the username and “tiger” is the password.
You can see a JSP sample in the
instructions for Windows.
Now that the test page is complete, use Eclipse to redeploy it to Apache Tomcat. In the Servers view, notice that State is set to Republish, because changes have been made since the project was last deployed to the server. RightCclick the server and select Publish from the menu. The state changes to Synchronized once the project has been deployed to the server. With the project successfully deployed and the server started, open a browser and navigate to http://localhost:9080/[ProjectName]/oracle_sample.jsp, where [ProjectName] is the name of the dynamic Web project you created. The new Web page you created appears.
STEP 7:
You can add Java servlets to your project and deploy them. To create a quick servlet you can use for testing purposes, use the Servlet Wizard by right clicking your dynamic Web project in the Project Explorer view and selecting New > Other. Under the Web folder, select Servlet, then click Next. Add the package name (e.g., cs4111) next to Java Package and add OracleServlet next to Class name. Click Finish. This is an example, so the defaults are fine. The Eclipse IDE generates a servlet class for you. To watch the test servlet in action, add a line in the doGet() method to print a message to the PrintWriter. The servlet class should look like the one shown below.
You can see a SERVLET
sample at http://www.cs.columbia.edu/~biliris/cs4111/projects/Proj1-3/sample.java
After you add the servlet, the Eclipse IDE notes that your project has changed. Look again at the Servers view; Restart now appears in the Status column next to the Tomcat server. To restart the server, right click the server in the Servers view, then select Restart > Start. Open a browser and navigate to http://localhost:9080/[ProjectName]/OracleServlet, where [ProjectName] is the name of your dynamic Web project.