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




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"
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.

Hi, I did exactly what you wrote,but sill my application cant connect to my data source, my context.xml file is containing the following defination: <?xml version="1.0" encoding="UTF-8"?> <Context path="/<my application name>" docBase="<my application name>" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/<>DB Name" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="<user name>" password="<password>" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/<db name>?autoReconnect=true"/> </Context> Still i get the following error: HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception com.sun.rave.web.ui.appbase.ApplicationException: javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: Error getting property 'gridPanel1' from bean of type kintest.Calibrator: java.lang.RuntimeException: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.destroy( com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView( com.sun.faces.lifecycle.RenderResponsePhase.execute( com.sun.faces.lifecycle.LifecycleImpl.phase( com.sun.faces.lifecycle.LifecycleImpl.render( javax.faces.webapp.FacesServlet.service( com.sun.rave.web.ui.util.UploadFilter.doFilter( note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs. -------------------------------------------------------------------------------- Apache Tomcat/5.0.28 Can you please help me with that. Thanks in advance!!! Eliad.

Posted by Eliad Dahan on October 28, 2006 at 11:22 PM MDT #

Nothing jumps about about the problem. Please post your question/comment to the Java Studio Creator forum at 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.


Posted by David Botterill on October 29, 2006 at 03:13 PM MST #

Ok thanks!!! Eliad.

Posted by Eliad Dahan on October 29, 2006 at 10:32 PM MST #

Hi Mr. David, I have successfully deplyed my project from Postgres DB in Sun Java Studio Creator on Apache Tomcat6 server. I even have generated graphs and charts using JSChart properly. But I need to generate reports using JasperReports1.2.8 or above. In the Sun.Com tutorial they only talk how to do JasperReports in JavaApplicationServer8.2 ( But I want to do it in Tomcat6. Could you please guide me through this? I just can't find server.policy file in Tomcat.. So I need any substitute or another method. Please just guide me. Thank you. Regards.

Posted by Dias on June 12, 2007 at 06:40 PM MDT #

I'm not very familiar with the JasperReports tutorial you mention. However, if you want specifics about security configurations in Tomcat, please see


Posted by David on June 13, 2007 at 03: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- /Applications/

Posted by christian johnsen on August 23, 2007 at 11:52 AM MDT #

hi David,
Could you please tell me how to deploy a project with postgres in tomcat6?

Thanky you

Posted by Dias on September 04, 2007 at 08:03 PM MDT #

Hello Mr. David,

I m new to JSF and netbeans. I am trying to develop a simple web application using netbeans 6.5 using tomcat 5.5. My Application is doing nothing but just saying hello. But problem is this that i m not allowed to use .war files. So the problem is this how to write context.xml and web.xml as these files , auto created by netbeans, are designed to use .war files. HELP ME PLEASE.

Posted by Abhilash on December 15, 2008 at 01:21 AM MST #


Please post your questions to or


Posted by David Botterill on December 15, 2008 at 01:28 AM MST #

Post a Comment:
  • HTML Syntax: NOT allowed

David Botterill


« February 2016