After the conversation we had in the comments I decided to go ahead and build a simple "hello world" locally to see if I can reproduce the issue. I had to go through some hoops but not the one you described. I now wonder if you have any conflicting version of jetty libraries on your classpath. Look at this question here, for example. And just in case, I had to deal with some other issues related to GWT hosted mode, class loading, and Hibernate (here, more, some more). It's all clear now and my simple example is working.
Back to your case. Looking through the patched Jetty launcher I figured what GWT was doing to Jetty's logging subsystem. Look at the JettyTreeLogger
inner class. It sends all INFO
and below to SPAM
. Unless you run the GWT app with the log level SPAM
you won't see the "precious" Jetty output you need to diagnose your case. So turn on SPAM log level in the run configuration (GWT tab) or alternatively patch the already patched launcher further not to swallow Jetty log messages.
Having followed the steps to set up my own Jetty Launcher and running GWT with log level SPAM I am able to see the following in the console:
...
Created java:comp/env for webapp /
Finding global env entries
...
parse: file:/.../JettyHibernateExample/war/WEB-INF/jetty-env.xml
...
loaded class com.mysql.jdbc.jdbc2.optional.MysqlDataSource from ContextLoader@null
XML new class com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
...
XML new class org.mortbay.jetty.plus.naming.Resource
...
Looking up name="jdbc"
Looking up binding for jdbc for context=env
...
Subcontext jdbc created
Adding binding with key=nndb obj=Reference Class Name: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
It successfully parses out the configuration and properly binds created objects. Further in the log:
May 30, 2012 5:27:33 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
...
DEBUG org.hibernate.cfg.Configuration -
hibernate.connection.datasource=java:comp/env/jdbc/nndb
...
DEBUG org.hibernate.internal.SessionImpl - Opened session at timestamp
DEBUG org.hibernate.internal.SessionImpl - Disconnecting session
DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing JDBC connection
A SessionFactory
was successfully instantiated, Session
opened and subsequently disconnected. I didn't test it further assuming it would be all good from here.
Here's the list of dependencies I have in my WEB-INF/lib
:
antlr-2.7.7.jar
dom4j-1.6.1.jar
gwt-servlet.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.3.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-validator-4.1.0.Final.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
jetty-naming-6.1.11.jar
jetty-plus-6.1.11.jar
logback-classic-1.0.1.jar
logback-core-1.0.1.jar
mysql-connector-java-5.1.20-bin.jar
report
slf4j-api-1.6.4.jar
validation-api-1.0.0.GA.jar
I hope with logs turned on you will finally see what gets in the way. Feel free to share it somewhere for us to look at it if you need further assistance.
UPDATE Now having your log file to inspect I will start making more recommendations. First thing I noticed is that your web.xml
doesn't seem to be following the DTD order of elements. Your resource-ref
should go after servlet
, servlet-mapping
, and welcome-file-list
. This doesn't seem to matter though.
Can you please tell me what exactly you mean when you say
@ different versions: project classpath: 6.1.26 but 6.1.11 in WEB-INF/lib
I want to make sure the classpath is not an issue and we don't have multiple jetty JARs conflicting in runtime. Please share your .classpath
project file along with the full listing of things in WEB-INF/lib
.
UPDATE 2 I figured a difference between the sequence of events in your log file and mine. I will cut to the chase.
In Jetty 6.1.11:
public void configureWebApp() throws Exception
{
//create a java:comp/env
createEnvContext();
//add java:comp/env entries for any globally defined EnvEntries
bindGlobalEnvEntries();
//set up java:comp/env as the Context in which to bind directly
//the entries in jetty-env.xml
NamingEntry.setScope(NamingEntry.SCOPE_LOCAL);
//check to see if an explicit file has been set, if not,
//look in WEB-INF/jetty-env.xml
....
}
while in Jetty 6.1.26:
public void configureWebApp() throws Exception
{
//check to see if an explicit file has been set, if not,
//look in WEB-INF/jetty-env.xml
...
}
and creating context is moved to:
public void configureDefaults() throws Exception
{
//create a java:comp/env
createEnvContext();
}
and it doesn't set SCOPE_LOCAL
. Without SCOPE_LOCAL
the root context is not java:comp/env
like it should be. Running with 6.1.26 (plus
and naming
) I can now see the "problematic":
Looking up binding for __ for context=null
That said, however, it works fine anyway. That "scope" logic has got to live in some other place now and as long as you have 6.1.26 (and no conflicting classes anywhere from earlier versions) it should work just fine. Where you have:
Looking up name="__/jdbc/nndb"
Looking up binding for __ for context=null
InitialContextFactory.getInitialContext()
Created initial context delegate for local namespace:org.mortbay.naming.local.localContextRoot@237c8a9c
InitialContextFactory.getInitialContext()
Created initial context delegate for local namespace:org.mortbay.naming.local.localContextRoot@457019f7
Looking up name="Server@1c9e8392/__/javax.sql.DataSource/default"
I have:
Looking up name="__/jdbc/nndb"
Looking up binding for __ for context=null
Looking up name="jdbc/nndb"
Looking up binding for jdbc for context=__
Looking up name="nndb"
Looking up binding for nndb for context=jdbc
InitialContextFactory.getInitialContext()
Created initial context delegate for local namespace:org.mortbay.naming.local.localContextRoot@1830f66
>>> new root context requested
Looking up name="comp/env"
Looking up binding for comp for context=null
Using classloader of current org.mortbay.jetty.handler.ContextHandler
Looking up name="env"
Looking up binding for env for context=comp
Binding java:comp/env/jdbc/nndb to jdbc/nndb
That said, straighten up your classpath and ensure you are running the 6.1.11 or 6.1.26 and not a mixture of the two. It should do it. And one more thing. Make sure you don't bring any custom JNDI stuff (like object factories) with the WEB-INF/classes
.