GWT 1.6 JNDI and MS SQL configuratio

June 29, 2009 by barciszewski

We’re now using GWT 1.6 at my work and we wanted to configure our applications to use JNDI.  Although there are a few blog posts on this topic, each left out a bit of information that would have been helpful in getting the system to work.  So I decided to put up a post here that goes step-by-step through my installation to help others who might have the same issues I did.  Where ever possible, I will also reference the original posts I had found, in case you’d like to look there.

My setup

First things first – here are the tools I’m using

  • Eclipse Ganymede with GWT Plugin
  • GWT 1.6
  • JTDS 1.2.2

Steps

1.  Create jetty-web.xml file in war/WEB-INF/
2.  Copy the following into jetty-web.xml

<?xml version=”1.0″?>
<!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://jetty.mortbay.org/configure.dtd”>
<Configure class=”org.mortbay.jetty.webapp.WebAppContext”>
<New id=”website” class=”org.mortbay.jetty.plus.naming.Resource”>
<Arg>java:comp/env/jdbc/dataSourceName</Arg>
<Arg>
<New class=”net.sourceforge.jtds.jdbcx.JtdsDataSource”>
<Set name=”DatabaseName”>(databaseName)</Set>
<Set name=”ServerName”>(serverName)</Set>
<Set name=”User”>(User)</Set>
<Set name=”Password”>(Password)</Set>
</New>
</Arg>
</New>
</Configure>

<?xml version=”1.0″?>
<!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://jetty.mortbay.org/configure.dtd”>
<Configure>
<New id=”website”>
<Arg>java:comp/env/jdbc/power_plus_dot_com</Arg>
<Arg>
<New>
<Set name=”DatabaseName”>power_plus_dot_com</Set>
<Set name=”ServerName”>sqlCluster</Set>
<!–<Set name=”url”>jdbc:jtds:sqlserver://sqlCluster:1433/power_plus_dot_com;user=website_user;password=dmfdWt2k</Set>–>
<Set name=”User”>website_user</Set>
<Set name=”Password”>dmfdWt2k</Set>
</New>
</Arg>
</New>
</Configure>

3.  Add Jetty Plus and Jetty Naming to your classpath

For this step, I created a new folder off the root of my GWT project called, “dependency”.  Please note that jetty-naming has a dependency on activation and mail.  So, the .jar files I have to import into my project are:

  • jetty-plus-6.1.12.jar
  • jetty-naming-6.1.12.jar
  • activation-1.1.jar
  • mail-1.4.jar

I want to deploy these applications to Tomcat, so I configured the launcher to include these on the classpath,  Run->Run Configurations…->Classpath->User Entries->Add JARS…

While configuring the laucher, add the following under Arguments->VM Arguments

-Djava.naming.factory.initial=org.mortbay.naming.InitialContextFactory

4.  In my code, I now get the connection with the following:

Context lContext = new InitialContext();

DataSource lDataSource = (DataSource) lContext.lookup(“java:comp/env/jdbc/dataSourceName”);

Connection connection = lDataSource.getConnection();

Alternate

If you want to use connection pooling or a different database, here is a link to the Jetty page that shows some sample configs: http://docs.codehaus.org/display/JETTY/DataSource+Examples

The most informative BLOG entry I found: http://humblecode.blogspot.com/2009/05/gwt-16-using-jndi-datasource.html

Dangerous AC Power

June 23, 2009 by barciszewski

Last night I had a real scare. I have work-issued Dell Inspiron notebook that I frequently use in the evenings. Last night, I went to do some work and when I plugged in the replacement AC Adapter, it LITERALLY blew up. Complete with column of fire(Albeit a little one), and burning ember.

It would not have been bad except that it was right in my face, so that little spark seemed a huge flame. I’m just glad that didn’t happen overnight, or I would Likely have more than an ember burn in my couch.

Hello world!

June 18, 2009 by barciszewski

Well, this first blog post kept the same title.  Considering that I plan on blogging about programming and development, I thought the title appropriate.  So, for this first post I thought I would introduce some of the topics I might blog about: GWT, ExtGWT, Hibernate, Spring. Any thoughts on what I should talk about would be welcome.