<docbook><section><title>JDBCAppServerTomcatLinux</title><para> </para><title> Using UDA with Apache Tomcat 5.5 (Linux) </title> Using UDA with Apache Tomcat 5.5 (Linux) 
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Required components </bridgehead>
<para>You will need to download the following components</para><itemizedlist mark="bullet" spacing="compact"><listitem>Tomcat - <ulink url="http://tomcat.apache.org">download</ulink> </listitem>
<listitem> Tomcat Administrator - <ulink url="http://tomcat.apache.org">download</ulink> </listitem>
<listitem> opltest.war Web Application - <ulink url="./JDBCAppServerTomcatLinux?att=opltest.war">download</ulink> </listitem>
<listitem> JDK - <ulink url="http://java.sun.com">download</ulink> </listitem>
<listitem> <ulink url="OpenLink">OpenLink</ulink> jar file - one of these, appropriate to the selected JDK/JRE -</listitem>
</itemizedlist>
<table><title /><tgroup><thead /><tbody>
<row />
<row><entry>  1.1  </entry><entry>  <ulink url="http://download.openlinksw.com">opljdbc.jar</ulink>  </entry></row>
<row><entry>  1.2 or 1.3  </entry><entry>  <ulink url="http://download.openlinksw.com">opljdbc2.jar</ulink>  </entry></row>
<row><entry>  1.4 or 1.5  </entry><entry>  <ulink url="http://download.openlinksw.com">opljdbc3.jar</ulink>  </entry></row>
<row><entry>  1.6  </entry><entry>  <ulink url="http://download.openlinksw.com">opljdbc4.jar</ulink>  </entry></row>
<row><entry>  1.7  </entry><entry>  <ulink url="http://download.openlinksw.com">opljdbc4_1.jar</ulink>  </entry></row>
<row><entry>  1.8  </entry><entry>  <ulink url="http://download.openlinksw.com">opljdbc4_2.jar</ulink>  </entry></row>
</tbody></tgroup></table>
<bridgehead class="http://www.w3.org/1999/xhtml:h2"> Install JDK </bridgehead>
<para>Install the JDK by running the *.bin, which automatically extracts the JDK.</para><para>NOTE: You may need to set the execute permission on the bin file before it can be executed.</para><para> </para><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Set Environment Variables </bridgehead>
<para>The following environment variables must be set -- </para><programlisting>  export JAVA_HOME=/usr/java/jre1.5.0_05
  export PATH=$PATH:/usr/java/jdk1.5.0_05/bin
</programlisting><para> The simplest way is to add these to your -- <computeroutput>~/.bash_profile=</computeroutput> (or similar, depending on <emphasis><emphasis>$SHELL</emphasis></emphasis>) to ensure they are set every time you log in.</para><para>NOTE: Paths to your Java installation will most likely differ!</para><para> </para><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Install Tomcat </bridgehead>
<para>Install Tomcat by running gunzip and tar against the downloaded <computeroutput>*.tar.gz</computeroutput> file, which will extract the archive into the current working directory.
</para><programlisting>gunzip *.tar.gz
tar -xvf *.tar
</programlisting><para> The root install directory of Tomcat will be known as; <computeroutput>CATALINA_HOME</computeroutput></para><para> </para><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Enable Tomcat Manager Web Application </bridgehead>
<para>Edit the file -- <computeroutput>$CATALINA_HOME/conf/tomcat-users.xml</computeroutput> to read -- </para><programlisting>&lt;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&gt;
	&lt;tomcat-users&gt;
		&lt;role rolename=&quot;tomcat&quot;/&gt;
		&lt;role rolename=&quot;role1&quot;/&gt;
		&lt;role rolename=&quot;manager&quot;/&gt;
		&lt;role rolename=&quot;admin&quot;/&gt;
		&lt;user username=&quot;tomcat&quot; password=&quot;tomcat&quot; roles=&quot;tomcat,manager,admin&quot;/&gt;
		&lt;user username=&quot;both&quot; password=&quot;tomcat&quot; roles=&quot;tomcat,role1&quot;/&gt;
		&lt;user username=&quot;role1&quot; password=&quot;tomcat&quot; roles=&quot;role1&quot;/&gt;
	 &lt;/tomcat-users&gt;
</programlisting><para> This will add the <emphasis><emphasis>manager</emphasis></emphasis> and <emphasis><emphasis>admin</emphasis></emphasis> roles, and allocate these roles to the <emphasis><emphasis>tomcat</emphasis></emphasis> user.</para><para>NOTE: Ensure the following is the first line of the file otherwise Tomcat will not start - </para><programlisting>&lt;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&gt;
</programlisting><para> Start Tomcat using the command -- <computeroutput>$CATALINA_HOME/bin/startup.sh</computeroutput></para><para>Browse to the following url to verify the Web Manager application is running -- <computeroutput>http://tomcat_server:8080/manager/http</computeroutput></para><para>This Web application will allow quick deployment of future Web applications.</para><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Install <ulink url="OpenLink">OpenLink</ulink> jar files </bridgehead>
<para>Copy the <computeroutput>.jar</computeroutput> file chosen for your JDK/JVM/JRE into the directory -- <computeroutput>$CATALINA_HOME/common/lib</computeroutput></para><para> Stop and restart Tomcat with the commands -- </para><programlisting>$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh
</programlisting><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Prepare the Web Application </bridgehead>
<para>Demonstrating how to build and deploy a Web application from the beginning is beyond the scope of this short tutorial so what follows is a quick method of altering the JDBC URLs and SQL statements in an existing Web application.</para><para>NOTE: Be careful when moving .war files about using Internet Explorer.
 Sometimes they will be renamed to .zip by Internet Explorer.</para><bridgehead class="http://www.w3.org/1999/xhtml:h3"> Rename the .war file to .zip </bridgehead>
<para>Rename - <computeroutput>opltest.war</computeroutput> -to- <computeroutput>opltest.zip</computeroutput></para><para>You will then be able to unzip the archive to get at the files inside it.
 (Some utilities can unzip the .war archive without renaming.) <computeroutput>unzip opltest.zip</computeroutput></para><bridgehead class="http://www.w3.org/1999/xhtml:h3"> Edit JDBC URLs </bridgehead>
<para>Edit the driver class and the JDBC connection URL in the file -- <computeroutput>/META-INF/context.xml</computeroutput></para><para>NOTE: Ensure that the edited file is placed back into the archive.
<computeroutput>zip -r ../opltest *</computeroutput></para><para> </para><bridgehead class="http://www.w3.org/1999/xhtml:h3"> Edit the SQL statement(s) </bridgehead>
<para>You will need to edit the SQL statement(s) in <emphasis>the following JSP files</emphasis> based on the chosen database determined by the JDBC URL in the file -- <computeroutput>/META-INF/context.xml</computeroutput></para><para>Edit the JSP files -- </para><programlisting>opljdbc.jsp
opljdbc2.jsp 
opljdbc3.jsp
</programlisting><para> There are two main areas of interest --</para><orderedlist spacing="compact"><listitem>The &lt;sql:query&gt; tag which select the datasource as defined in - <computeroutput>/META-INF/context.xml</computeroutput> which contains the SQL query itself --  <computeroutput>&lt;sql:query var=&quot;resultset&quot; dataSource=&quot;jdbc/opljdbc2&quot;&gt;		select SupplierID, CompanyName, ContactName, ContactTitle from Suppliers	&lt;/sql:query&gt;</computeroutput> 		 </listitem>
<listitem>The one or more ${row.column_name} constructs that output data as per the SQL query  <computeroutput>${row.SupplierID}${row.CompanyName} </computeroutput></listitem>
</orderedlist><para> NOTE: Ensure that the edited file is placed back into the archive.
<computeroutput>zip -r ../opltest *</computeroutput></para><bridgehead class="http://www.w3.org/1999/xhtml:h3"> Rename the .zip file back to .war </bridgehead>
<para>Rename the file <computeroutput>opltest.zip</computeroutput> back to <computeroutput>opltest.war</computeroutput></para><bridgehead class="http://www.w3.org/1999/xhtml:h2"> Deploy opltest Web Application </bridgehead>
<para>Open the Tomcat Manager -- <computeroutput>http://tomcat_server:8080/manager/http</computeroutput></para><para>Scroll down to the &quot;War file to deploy&quot; section.</para><para>Use the &quot;Browse...&quot; button to browse to the file -- <computeroutput>opltest.war</computeroutput></para><para>Finally, click the &quot;Deploy&quot; button.</para><para>The screen will refresh and you should see the new application in the list with its &quot;Running&quot; property set to true.</para><para>The newly deployed application is now available at the following URL -- <computeroutput>http://tomcat_server:8080/opltest</computeroutput></para></section></docbook>