Sunday, December 26, 2010

The first ever my own blog post

This is my first ever blog & my own blog post. There's not much to say but I'll guarantee that this blog will be useful for anybody since I'll share my research knowledge & experience on anything & everything. 


So keep blogging........ enjoy

Problems found when I wanted to run a simple EJB 2.0 application with eclipse in a JBoss server

I got this idea of running an EJB app on my own. Since google is there, i never thought it would be that difficult & time consuming. But as you might have already experienced there is plenty of on-line resources. That's too much & I found the answers for my simple problems after hours of investigations. So this is a simple effort for those who suffered like me
  • eclipse Java EE IDE for Web Developers
  • JBoss 4.0.0
  • JDK 1.6.17
I found a simple session bean server side code compiled & already in a jar file. So simply I put that in the jboss server - default instance folder & re-started the server. The ejb got deployed properly as I could see that in the jboss console. Got the client code & tried to run it.

problem 1
com.sun.enterprise.config.ConfigException: Error refreshing ConfigContext
cause: D:\Studies\Java\config\system-server-config.xml (The system cannot find the path specified)

The problem here is JBoss can't locate the jndi.properties. So you can do the following. Explicitly configure jndi properties & provide that as argument when instantiating InitialContext. 

Solution
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url", "localhost:1099");

The following 3 lines do the same

properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "localhost:1099");

Problem 2
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

Solution
Add jbossall-client.jar & jnp-client.jar to the classpath of the client project

Note
You need to add j2ee.jar since this is related to ejbs