Wednesday August 09, 2006
Defining Java Studio Creator 2 Data Sources in Tomcat
I'm sure this will be old information to some people. But, I had
the need to look at a Java Studio Creator 2 web application in Tomcat
5.5 the other day and I needed to define the sample Travel database in
JavaDB to the Tomcat container. There is a good help topic on
this in Java Studio Creator 2 than can easily be found by searching on
"tomcat". The first hit is "Deployment Example: Tomcat".
This will give you most of the necessary information. In
this blog I'll give you some critical pieces to allow you to talk to
the sample database in JavaDB bundled with Java Studio Creator 2.
Yes this applies to Java Studio Creator 2 Update 1 as well.
Copying the JavaDB JDBC Jar File
First, you will need to copy the JavaDB JDBC Jar file to the Tomcat
container so Tomcat can load the JDBC driver when needed. To do
this, copy
creator_install_dir/SunAppserver8/derby/lib/derbyclient.jar
to
tomcat_install_dir/common/lib.
Add a "context.xml" to Your Project
Next you will need to define the data resource to the Tomcat container.
There are really two places a JNDI (Java Naming and Directory
Interface) data resource needs to be defined. The first place is
in the application itself. This definition is taken care of by
Java Studio Creator in the "web.xml" file via the
"<resource-ref>" element. The other definition needs to be
in the container. In Tomcat, this can be in the "server.xml" file
which will be applicable for every web application or in a
"context.xml" in the web application's "META-INF" directory.
Here are the steps to create the "context.xml" file for your Java Studio Creator 2 web application.
1. Add a directory called "
META-INF"
to your project by selecting the "File" window, then the "web"
directory. Right-click on the "web" directory and select
"New->Folder". When the dialog comes up, name the folder
"META-INF" and hit the "Finish" button.
2. Add a "context.xml" file to the
"META-INF" directory by selecting the "File" window, then the
"web/META-INF" directory. Right-click
on the "web/META-INF" directory and select "New->File/Folder...".
When the "New File" dialog appears, select "Resources->XML
Document". Select "Next" and name the XML Document "context.xml".
Select "Next" and choose "Well-formed Document". Press
"Finish". When the "context.xml" file appears in the editor,
replace the contents with the following and save the file.
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/CorporateTravelCenter" docBase="CorporateTravelCenter"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/Travel" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="travel" password="travel" driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:21527/sample"/>
</Context>
Lastly, you'll want to "clean and build" your project. Now when
you create a WAR file, the context.xml file will be part of it and used
by Tomcat to setup the data resource.
Posted by david
( Aug 09 2006, 05:55:52 PM MDT )
Permalink

|

|
Trackback URL: http://blogs.sun.com/david/entry/defining_java_studio_creator_2
Posted by Eliad Dahan on October 29, 2006 at 06:22 AM MST #
Nothing jumps about about the problem. Please post your question/comment to the Java Studio Creator forum at http://swforum.sun.com/jive/forum.jspa?forumID=123 so you can get help from the community. If your question still isn't answered, please email me your project so I can have a look.
Thanks!
-David
Posted by David Botterill on October 29, 2006 at 11:13 PM MST #
Posted by Eliad Dahan on October 30, 2006 at 06:32 AM MST #
Posted by Dias on June 13, 2007 at 01:40 AM MDT #
I'm not very familiar with the JasperReports tutorial you mention. However, if you want specifics about security configurations in Tomcat, please see http://tomcat.apache.org/tomcat-6.0-doc/security-manager-howto.html.
Thanks!
-David
Posted by David on June 13, 2007 at 10:32 AM MDT #
The paths have changed since this article was written. This is the current path on OS X with the cp command as you would use in you shell:
NbUser$ cp /Users/NbUser/.netbeans/5.5/db-derby-10.1.3.1-bin/lib/derbyclient.jar /Applications/NetBeans.app/Contents/Resources/NetBeans/enterprise3/apache-tomcat-5.5.17/common/lib/derbyclient.jar
Posted by christian johnsen on August 23, 2007 at 06:52 PM MDT #
hi David,
Could you please tell me how to deploy a project with postgres in tomcat6?
Thanky you
Dias
Posted by Dias on September 05, 2007 at 03:03 AM MDT #