[jboss-user] [Beginners Corner] - No InitialContext Exception

denisputnam do-not-reply at jboss.com
Sun Nov 2 18:56:02 EST 2008


Hi,

I am reading the "Enterprise JavaBeans 3.0" book from O'Reilly, and I am getting the following error.  I am using JBoss 4.x and JDK 6.0 with
MyEclipse.  I have included the error and the code.

I apologize for all the text, but I don't know what you need to tell me what to do.  Thank you for any help.

-Denis

The Client code:

	public static Context getInitialContext() throws javax.naming.NamingException
	{
		Properties p = new Properties();
		// Specify the JNDI properties specific to JBOSS
		p.put( Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
		p.put( Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );
		p.put( Context.PROVIDER_URL, "jnp://localhost:1099" );
		InitialContext initContext = new InitialContext(p);
		return initContext;
	}

The TravelAgent Bean code:

package com.titan.travelagent;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.titan.domain.Cabin;

@Stateless
public class TravelAgent implements TravelAgentRemote
{
	@PersistenceContext( unitName="TitanCruisesPU" ) private EntityManager manager;

	public void createCabin( Cabin cabin )
	{
		// TODO Auto-generated method stub
		manager.persist( cabin );
		
	}

	public Cabin findCabin( int pKey )
	{
		// TODO Auto-generated method stub
		return manager.find( Cabin.class, pKey );
	}

}

The Cabin Bean code:

// default package
package com.titan.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Cabin entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "cabin", catalog = "titan_cruises")
public class Cabin implements java.io.Serializable
{

	// Fields

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 4558984274428476870L;
	private Integer				id;
	private Integer				shipId;
	private Integer				bedCount;
	private String				name;
	private Integer				deckLevel;

	// Constructors

	/** default constructor */
	public Cabin()
	{
	}

	/** minimal constructor */
	public Cabin(Integer id)
	{
		this.id = id;
	}

	/** full constructor */
	public Cabin(Integer id, Integer shipId, Integer bedCount, String name,
			Integer deckLevel)
	{
		this.id = id;
		this.shipId = shipId;
		this.bedCount = bedCount;
		this.name = name;
		this.deckLevel = deckLevel;
	}

	// Property accessors
	@Id
	@Column(name = "ID", unique = true, nullable = false)
	public Integer getId()
	{
		return this.id;
	}

	public void setId( Integer id )
	{
		this.id = id;
	}

	@Column(name = "SHIP_ID")
	public Integer getShipId()
	{
		return this.shipId;
	}

	public void setShipId( Integer shipId )
	{
		this.shipId = shipId;
	}

	@Column(name = "BED_COUNT")
	public Integer getBedCount()
	{
		return this.bedCount;
	}

	public void setBedCount( Integer bedCount )
	{
		this.bedCount = bedCount;
	}

	@Column(name = "NAME", length = 30)
	public String getName()
	{
		return this.name;
	}

	public void setName( String name )
	{
		this.name = name;
	}

	@Column(name = "DECK_LEVEL")
	public Integer getDeckLevel()
	{
		return this.deckLevel;
	}

	public void setDeckLevel( Integer deckLevel )
	{
		this.deckLevel = deckLevel;
	}

}

The persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
    
	<persistence-unit name="TitanCruisesPU" transaction-type="JTA">
  		<jta-data-source>java:MySqlDS</jta-data-source>
	</persistence-unit>
  


jboss-cmp:

<!DOCTYPE jboss-jdbc PUBLIC
	"-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"
	"http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd" >

<jbosscomp-jdbc>
	
		java:MySqlDS
		<datasource-mapping>mySQL</datasource-mapping>
	
</jbosscomp-jdbc>


The error exception:

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
	at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
	at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
	at javax.naming.InitialContext.init(Unknown Source)
	at javax.naming.InitialContext.(Unknown Source)
	at com.titan.clients.Client.getInitialContext(Client.java:61)
	at com.titan.clients.Client.main(Client.java:29)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
	... 6 more

The server startup log:

18:41:52,100 INFO  [Server] Starting JBoss (MX MicroKernel)...
18:41:52,101 INFO  [Server] Release ID: JBoss [Trinity] 4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)
18:41:52,102 INFO  [Server] Home Dir: D:\jboss-4.2.3.GA
18:41:52,103 INFO  [Server] Home URL: file:/D:/jboss-4.2.3.GA/
18:41:52,109 INFO  [Server] Patch URL: null
18:41:52,109 INFO  [Server] Server Name: default
18:41:52,109 INFO  [Server] Server Home Dir: D:\jboss-4.2.3.GA\server\default
18:41:52,109 INFO  [Server] Server Home URL: file:/D:/jboss-4.2.3.GA/server/default/
18:41:52,109 INFO  [Server] Server Log Dir: D:\jboss-4.2.3.GA\server\default\log
18:41:52,109 INFO  [Server] Server Temp Dir: D:\jboss-4.2.3.GA\server\default\tmp
18:41:52,110 INFO  [Server] Root Deployment Filename: jboss-service.xml
18:41:52,618 INFO  [ServerInfo] Java version: 1.5.0_11,Sun Microsystems Inc.
18:41:52,618 INFO  [ServerInfo] Java VM: Java HotSpot(TM) Client VM 1.5.0_11-b03,Sun Microsystems Inc.
18:41:52,618 INFO  [ServerInfo] OS-System: Windows Vista 6.0,x86
18:41:53,153 INFO  [Server] Core system initialized
18:41:56,473 INFO  [WebService] Using RMI server codebase: http://127.0.0.1:8083/
18:41:56,476 INFO  [Log4jService$URLWatchTimerTask] Configuring from URL: resource:jboss-log4j.xml
18:41:57,083 INFO  [TransactionManagerService] JBossTS Transaction Service (JTA version) - JBoss Inc.
18:41:57,084 INFO  [TransactionManagerService] Setting up property manager MBean and JMX layer
18:41:57,328 INFO  [TransactionManagerService] Starting recovery manager
18:41:57,468 INFO  [TransactionManagerService] Recovery manager started
18:41:57,469 INFO  [TransactionManagerService] Binding TransactionManager JNDI Reference
18:42:01,731 INFO  [EJB3Deployer] Starting java:comp multiplexer
18:42:04,938 INFO  [NativeServerConfig] JBoss Web Services - Native
18:42:04,938 INFO  [NativeServerConfig] jbossws-3.0.1-native-2.0.4.GA (build=200803312044)
18:42:06,430 INFO  [Embedded] Catalina naming disabled
18:42:06,658 INFO  [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\MyEclipse 6.5\bin
18:42:06,749 INFO  [Http11Protocol] Initializing Coyote HTTP/1.1 on http-127.0.0.1-8080
18:42:06,762 INFO  [AjpProtocol] Initializing Coyote AJP/1.3 on ajp-127.0.0.1-8009
18:42:06,762 INFO  [Catalina] Initialization processed in 332 ms
18:42:06,763 INFO  [StandardService] Starting service jboss.web
18:42:06,765 INFO  [StandardEngine] Starting Servlet Engine: JBossWeb/2.0.1.GA
18:42:06,832 INFO  [Catalina] Server startup in 69 ms
18:42:06,991 INFO  [TomcatDeployer] deploy, ctxPath=/, warUrl=.../deploy/jboss-web.deployer/ROOT.war/
18:42:07,868 INFO  [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=.../deploy/http-invoker.sar/invoker.war/
18:42:08,065 INFO  [TomcatDeployer] deploy, ctxPath=/jbossws, warUrl=.../deploy/jbossws.sar/jbossws-context.war/
18:42:08,211 INFO  [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=.../deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/
18:42:09,437 INFO  [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=.../deploy/management/console-mgr.sar/web-console.war/
18:42:10,198 INFO  [MailService] Mail Service bound to java:/Mail
18:42:10,464 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-local-jdbc.rar
18:42:10,512 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-xa-jdbc.rar
18:42:10,558 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-local-jdbc.rar
18:42:10,614 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-xa-jdbc.rar
18:42:10,694 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jms/jms-ra.rar
18:42:10,815 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/mail-ra.rar
18:42:10,868 INFO  [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/quartz-ra.rar
18:42:10,880 INFO  [QuartzResourceAdapter] start quartz!!!
18:42:10,978 INFO  [SimpleThreadPool] Job execution threads will use class loader of thread: main
18:42:11,008 INFO  [QuartzScheduler] Quartz Scheduler v.1.5.2 created.
18:42:11,011 INFO  [RAMJobStore] RAMJobStore initialized.
18:42:11,012 INFO  [StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
18:42:11,012 INFO  [StdSchedulerFactory] Quartz scheduler version: 1.5.2
18:42:11,012 INFO  [QuartzScheduler] Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
18:42:11,938 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'
18:42:12,332 INFO  [A] Bound to JNDI name: queue/A
18:42:12,342 INFO  [B] Bound to JNDI name: queue/B
18:42:12,343 INFO  [C] Bound to JNDI name: queue/C
18:42:12,344 INFO  [D] Bound to JNDI name: queue/D
18:42:12,346 INFO  [ex] Bound to JNDI name: queue/ex
18:42:12,368 INFO  [testTopic] Bound to JNDI name: topic/testTopic
18:42:12,369 INFO  [securedTopic] Bound to JNDI name: topic/securedTopic
18:42:12,371 INFO  [testDurableTopic] Bound to JNDI name: topic/testDurableTopic
18:42:12,374 INFO  [testQueue] Bound to JNDI name: queue/testQueue
18:42:12,423 INFO  [UILServerILService] JBossMQ UIL service available at : /127.0.0.1:8093
18:42:12,475 INFO  [DLQ] Bound to JNDI name: queue/DLQ
18:42:12,643 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA'
18:42:12,767 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'
18:42:13,337 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.entity.PersistenceUnitDeployment
18:42:13,341 INFO  [JmxKernelAbstraction] installing MBean: persistence.units:jar=TitanCruises.jar,unitName=TitanCruisesPU with dependencies:
18:42:13,341 INFO  [JmxKernelAbstraction] 	jboss.jca:name=MySqlDS,service=DataSourceBinding
18:42:13,344 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.units:jar=TitanCruises.jar,unitName=TitanCruisesPU
18:42:13,379 INFO  [Version] Hibernate EntityManager 3.2.1.GA
18:42:13,406 INFO  [Version] Hibernate Annotations 3.2.1.GA
18:42:13,416 INFO  [Environment] Hibernate 3.2.4.sp1
18:42:13,433 INFO  [Environment] hibernate.properties not found
18:42:13,436 INFO  [Environment] Bytecode provider name : javassist
18:42:13,442 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
18:42:13,627 INFO  [Ejb3Configuration] found EJB3 Entity bean: com.titan.domain.Cabin
18:42:13,662 INFO  [Configuration] Reading mappings from resource : META-INF/orm.xml
18:42:13,665 INFO  [Ejb3Configuration] [PersistenceUnit: TitanCruisesPU] no META-INF/orm.xml found
18:42:13,744 INFO  [AnnotationBinder] Binding entity from annotated class: com.titan.domain.Cabin
18:42:13,827 INFO  [EntityBinder] Bind entity com.titan.domain.Cabin on table cabin
18:42:14,075 INFO  [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
18:42:14,079 INFO  [InjectedDataSourceConnectionProvider] Using provided datasource
18:42:14,504 INFO  [SettingsFactory] RDBMS: MySQL, version: 5.1.28-rc-community
18:42:14,504 INFO  [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
18:42:14,538 INFO  [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
18:42:14,546 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
18:42:14,554 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
18:42:14,564 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
18:42:14,564 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
18:42:14,564 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
18:42:14,565 INFO  [SettingsFactory] JDBC batch size: 15
18:42:14,565 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
18:42:14,566 INFO  [SettingsFactory] Scrollable result sets: enabled
18:42:14,566 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
18:42:14,566 INFO  [SettingsFactory] Connection release mode: auto
18:42:14,568 INFO  [SettingsFactory] Maximum outer join fetch depth: 2
18:42:14,568 INFO  [SettingsFactory] Default batch fetch size: 1
18:42:14,568 INFO  [SettingsFactory] Generate SQL with comments: disabled
18:42:14,568 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
18:42:14,568 INFO  [SettingsFactory] Order SQL inserts for batching: disabled
18:42:14,568 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
18:42:14,575 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
18:42:14,575 INFO  [SettingsFactory] Query language substitutions: {}
18:42:14,575 INFO  [SettingsFactory] JPA-QL strict compliance: enabled
18:42:14,575 INFO  [SettingsFactory] Second-level cache: enabled
18:42:14,575 INFO  [SettingsFactory] Query cache: disabled
18:42:14,575 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
18:42:14,577 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
18:42:14,577 INFO  [SettingsFactory] Cache region prefix: TitanCruises_jar,TitanCruisesPU
18:42:14,577 INFO  [SettingsFactory] Structured second-level cache entries: disabled
18:42:14,587 INFO  [SettingsFactory] Statistics: disabled
18:42:14,588 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
18:42:14,589 INFO  [SettingsFactory] Default entity-mode: pojo
18:42:14,589 INFO  [SettingsFactory] Named query checking : enabled
18:42:14,902 INFO  [SessionFactoryImpl] building session factory
18:42:15,200 INFO  [SessionFactoryObjectFactory] Factory name: persistence.units:jar=TitanCruises.jar,unitName=TitanCruisesPU
18:42:15,202 INFO  [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
18:42:15,206 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.units:jar=TitanCruises.jar,unitName=TitanCruisesPU
18:42:15,207 WARN  [SessionFactoryObjectFactory] InitialContext did not implement EventContext
18:42:15,207 INFO  [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
18:42:15,416 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer
18:42:15,421 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=TitanCruises.jar,name=TravelAgent,service=EJB3 with dependencies:
18:42:15,421 INFO  [JmxKernelAbstraction] 	persistence.units:jar=TitanCruises.jar,unitName=TitanCruisesPU
18:42:15,466 INFO  [EJBContainer] STARTED EJB: com.titan.travelagent.TravelAgent ejbName: TravelAgent
18:42:15,544 INFO  [EJB3Deployer] Deployed: file:/D:/jboss-4.2.3.GA/server/default/deploy/TitanCruises.jar/
18:42:15,624 INFO  [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
18:42:15,858 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
18:42:15,885 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
18:42:15,896 INFO  [Server] JBoss (MX MicroKernel) [4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)] Started in 23s:784ms




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

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



More information about the jboss-user mailing list