Jetty, JNDI, Postgresql: Class not found

java, jetty, jndi, postgresql, postgresql-9.1

Solution

You need to add postgresql-9.1-901.jdbc4.jar to `$JETTY_HOME/lib/ext`.

This is because jetty initializes the JNDI context before it loads the classes from your WAR.

Problem

I'm trying to set up a JNDI DataSource in Jetty. In the start.ini file I have add the jetty-plus.xml file and the Options look like this: ``` OPTIONS=Server,resources,websocket,ext,plus,annotations ``` Then I'm adding the resource in my context file: ``` <New id="Traildevils" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg/> <Arg>jdbc/Traildevils</Arg> <Arg> <New class="org.postgresql.ds.PGConnectionPoolDataSource"> <Set name="User">recom</Set> <Set name="Password">recom</Set> <Set name="DatabaseName">Traildevils</Set> <Set name="ServerName">localhost</Set> <Set name="PortNumber">5432</Set> </New> </Arg> </New> ``` The postgresql-9.1-901.jdbc4.jar file is in the WEB-INF/lib of my war file. When I'm now trying to start the jetty I get the following error: ``` 2012-04-12 12:58:09.723:WARN:oejx.XmlConfiguration:Config error at <New id="Traildevils" class="org.eclipse.jetty.plus.jndi.Resource"><Arg/> <Arg>jdbc/Traildevils</Arg> <Arg>|???<New class="org.postgresql.ds.PGConnectionPoolDataSource"> <Set name="User">recom</Set> <Set name="Password">recom</Set> <Set name="DatabaseName">Traildevils</Set> <Set name="ServerName">localhost</Set><Set name="PortNumber">5432</Set></New>|??</Arg></New> java.lang.ClassNotFoundException: org.postgresql.ds.PGConnectionPoolDataSource ``` What did I miss?

Original source