200 likes | 229 Views
Learn how to set up, run, and migrate to Tomcat for efficient development and production environments. Includes instructions for configuring datasources and build tasks.
E N D
In this presentation… • Setting up tomcat on your machine • Setting up tomcat through MyEclipse • Running tomcat through MyEclipse • Setting up your project to run in tomcat in development • Setting up your project to run in tomcat in test and production • Migrating from JBoss to Tomcat • Tomcat test and production resources • build.properties file for tomcat • build.xml file for tomcat • Setting up tomcat datasources
Why move? • Less of a memory footprint • More reliable test environment • Easier to understand • Development easier and much quicker • SIT Recommendation: Everyone that does not need EJB should move to Tomcat.
Setting up tomcat on your machine • Extract tomcat into your /java/servers directory • https://docs.onestart.iu.edu/dav/MY/channels/Documentation/downloads/jakarta-tomcat-5.0.28.zip • Oracle jars (i.e.: UIS_java_lib/oracle-10.1.0.2.0/ojdbc14.jar) go in tomcat’s common/lib directory
Running tomcat through MyEclipse • Use the running man icon • Tomcat 5 • Start Tomcat • Stop Tomcat
Setting up your project to run in tomcat in development • Tomcat 5 now uses context.xml files • Runs your application from a specified location • Hot deploy (on save) • Relieves the dependency on MyEclipse for deployment • You need to add: /java/servers/jakarta-tomcat-5.0.28/conf/Catalina/localhost/<app>-<env>.xml
Example context.xml <Context path="/fo-dev" reloadable="true" docBase="c:/java/projects/FISCALOFFICER/fo"> <!-- datasources go here --> </Context>
Setting up your project to run in tomcat in test and prod • Leverage the existing deployment setup used in the JBoss environment • appdeploy ... • Context.xml file changes where the docBase points • Context.xml should go in your META-INF directory and be named context.xml
Cont. • Example <Context path="/<app>-<env>" reloadable="true" docBase="/usr/local/tomcat/<appserver>/webapps/<app>-<env>.war"> </Context> • Your ant dist task should replace the <env> with the correct test or prod environment.
Cont. • Example <replaceregexp match="\b(dev|unt|reg|stg|trn|prd)\b" replace="${build.environment}" byline="true" flags="g"> <fileset dir="."> <include name="${webapp}/META-INF/context.xml" /> </fileset> </replaceregexp>
Migrating from JBoss to Tomcat • Send a request to: j2ee-request@iu.edu
Tomcat test and production resources • Deployment Test Server • x1j2ee • Deployment Prod Server • penguin01 • Test Servers • x3j2ee • x4j2ee • Prod Servers • penguin03 • penguin04
build.properties file for tomcat • /opt/ears/<env>/<app> project.cvs.root=:pserver:anonymous@es01.uits.indiana.edu:/srcctrl/CVS project.cvs.package=SIT/FISCALOFFICER project.cvs.anonpassword=***** project.home=SIT/FISCALOFFICER project.server=sit2 appserver.home=/usr/local/tomcat/default appserver.lib.dir=/usr/local/tomcat/default/common/lib appserver.deploy.dir=/usr/local/tomcat/sit2/webapps
build.xml file for tomcat • dist task only needs to build a war and a web.zip • dist task should also change the <ENV> for context.xml and web.xml • There is a different jsp compiler than for JBoss • See a full example in: SIT/FISCALOFFICER
Setting up tomcat datasources • Creates a database pool managed by Jakarta DBCP • <webapp>/META-INF/context.xml between the <Context> tags • Add a <resource-ref> block to your web.xml • Example on the next page
<!DOCTYPE doc [ <!ENTITY ENDB SYSTEM "file:/opt/sa_forms/java/unt/edu/iu/uis/security/fo/ENDB.xml"> ] > <Context path="/<app>-<env>" reloadable="true" docBase="/usr/local/tomcat/sit2/webapps/fo-unt.war"> <Resource name="jdbc/dev/fo/XA/EDEN" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/dev/fo/XA/EDEN"> <parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter> <parameter> <name>maxActive</name> <value>100</value> </parameter> <parameter> <name>maxIdle</name> <value>5</value> </parameter> <parameter> <name>maxWait</name> <value>10000</value> </parameter> &ENDB; <!-- rename this to your file --> <parameter> <name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value> </parameter> <parameter> <name>validationQuery</name> <value>select 1 from dual</value> </parameter> </ResourceParams> </Context>
Extract sensitive information /opt/sa_forms/java/<env>/edu/iu/uis/security/<app>/<app><resource>.xml <parameter> <name>username</name> <value>USERNAME</value> </parameter> <parameter> <name>password</name> <value>PASSWORD</value> </parameter> <parameter> <name>url</name> <value>jdbc:oracle:thin:@es01.uits.indiana.edu:1521:GEN1TST</value> </parameter>
web.xml addition <resource-ref> <description>MY Datasource</description> <res-ref-name> jdbc/dev/my/MYDB </res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>