[jboss-user] [Beginners Corner] - Cannot instantiate class: org.jnp.interfaces.NamingContextF

JuliaF do-not-reply at jboss.com
Sun Mar 30 13:28:50 EDT 2008


Hello

I tried to deploy and run a simple EJB tester app on JBoss 5 beta using a SessionBean and I am getting the following exception
-----------------------
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory 
[Root exception is java.lang.ClassNotFoundException:org.jnp.interfaces.NamingContextFactory]
-----------------------
I have tried different approaches but with no luck.

The structure of  my simple_session.ear file deployed in %JBOSS_HOME%/server/default/deploy is this:

simple_session/META-INF/Applicaiton.xml
simple_session/META-INF/MANIFEST.MF
simple_session/beans.jar
simple_session/client.jar
beans.jar consists of 
lemonpress\beans\SimpleSession.class
lemonpress\beans\SimpleSessionBean.class
META-INF\ejb-jar.xml
META-INF\MANIFEST.MF
client.jar consists of 
lemonpress\client\SimpleSessionClient.class
META-INF\applicaiton-client.xml
META-INF\MANIFEST.MF
jndi.properties


The source of lemonpress\client\SimpleSessionClient.class in client.jar
package lemonpress.client;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import lemonpress.beans.SimpleSession;


public class SimpleSessionClient {

	public static void main(String args[]) throws NamingException{
		
		System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
		System.setProperty("java.naming.provider.url", "localhost:1099"); 
		System.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
		
		Properties properties = new Properties();
	    	properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
	    	properties.put(Context.PROVIDER_URL, "localhost:8080");
	    	properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

		InitialContext ctx = new InitialContext();
		SimpleSession ss = (SimpleSession) ctx.lookup(SimpleSession.class.getName());
		System.out.println("lookup returned " + ss.toString());
		String result = ss.getEchoString("It has worked");
		System.out.println(result);
		
	}
}

As a measure of desperation I also included the file
jndi.properties in client.jar
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099

and referenced it in client\META-INF\MANIFEST.MF
Manifest-Version: 1.0
Class-Path: beans.jar jndi.properties
Main-Class: lemonpress.client.SimpleSessionClient

initially I ran the project as

simple_session> java -jar client.jar

Then after reading about in forums (sadly, mostly relating to Jboss 4.x and not much on 5.x) 
I came to adding more and more code to the SimpleSessionClient.java and modifying way to run the client.jar 
to resolve this issue of binding the interface to the the JNDI Factory class that should return the missing Application Context. 
Apart from blown up code in the SimpleSessionClient 
other things that I tried include running the client.jar as
A)
simple_session> java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost:1099 -jar client.jar

B) 
simple_session> set CLASSPATH=.;C:\jboss\client\jbossall-client.jar;C:\jboss\lib\concurrent.jar;C:\jboss\lib\jboss-common-core.jar;C:\jboss\lib\jboss-aop-jdk50.jar;C:\jboss\client\concurrent.jar;C:\jboss\client\jboss-common-client.jar;C:\jboss\client\jboss-javaee.jar;C:\jboss\client\jboss-transaction-client.jar;C:\jboss\client\jbosssx-client.jar;C:\jboss\client\jnp-client.jar;C:\jboss\server\default\lib\commons-httpclient.jar;C:\jboss\server\default\lib\jboss.jar;C:\jboss\server\default\lib\jboss-remoting.jar;C:\jboss\server\default\lib\jnpserver.jar;C:\jboss\server\default\deployers\ejb3.deployer\jboss-ejb3.jar;C:\jboss\server\default\deployers\jboss-aop-jboss5.deployer\jboss-aspect-library-jdk50.jar;

simple_session> java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -Djava.naming.provider.url=localhost:1099 -jar client.jar

As you can see I tried a few different ways of including reference to JNDI to my client but with no avail.

I start JBoss with default configuration and it does recognize and register my SimpleSessionBean in JNDI
In startup output it gives only one WARN message
17:02:27,265 WARN  [QuartzTimerServiceFactory] sql failed: CREATE TABLE qrtz_job_details(JOB_NAME VARCHAR(80) NO
T NULL, JOB_GROUP VARCHAR(80) NOT NULL, DESCRIPTION VARCHAR(120) NULL, JOB_CLASS_NAME VARCHAR(128) NOT NULL, IS_
DURABLE VARCHAR(1) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, IS_STATEFUL VARCHAR(1) NOT NULL, REQUESTS_RECOVERY
 VARCHAR(1) NOT NULL, JOB_DATA BINARY NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP))
However, later it says
17:02:29,437 INFO  [StdSchedulerFactory] Quartz scheduler 'JBossEJB3QuartzScheduler' initialized from an externally provided properties instance.
17:02:29,437 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.5.2
....
17:03:01,484 INFO  [StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'

It binds JNDI  
 17:02:25,328 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'

And registers my SimpleSessionBean
17:03:03,343 INFO  [MCKernelAbstraction] installing bean: jboss.j2ee:ear=simple_session.ear,jar=client.jar,name=client,service=EJB3 with dependencies:
17:03:03,343 INFO  [MCKernelAbstraction]   and supplies:
17:03:03,640 INFO  [ClientENCInjectionContainer] STARTED CLIENT ENC CONTAINER: client
17:03:08,062 INFO  [MCKernelAbstraction] installing bean: jboss.j2ee:ear=simple_session.ear,jar=beans.jar,name=SimpleSessionBean,service=EJB3 with dependencies:
17:03:08,062 INFO  [MCKernelAbstraction]   and supplies:
17:03:08,078 INFO  [MCKernelAbstraction]        Class:lemonpress.beans.SimpleSession
17:03:10,812 INFO  [EJBContainer] STARTED EJB: lemonpress.beans.SimpleSessionBean ejbName: SimpleSessionBean

Could anyone help me to resolve this seemingly dead-end situation?

Many thanks




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139939#4139939

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139939



More information about the jboss-user mailing list