• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB3 NotInitialContextException

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Please I need help with NetBeans ,running GlassFish & EJB3.


The Remote Interface:


package ejb;
import javax.ejb.Remote;

/**
* This is the business interface for AdiosNY enterprise bean.
*/
@Remote
public interface AdiosNYRemote {
public String Mensaje();


}






The Stateless Bean:


AdiosNYBean.java
*
* Created on May 26, 2007, 4:20 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package ejb;
import javax.ejb.Stateless;
/**
*
* @author HANDAL
*/
@Stateless(mappedName="Alpha")
public class AdiosNYBean implements ejb.AdiosNYRemote {
public String Mensaje(){
System.out.println("Viva el Peru");
return "Peru tierra de Heroes";

}

/** Creates a new instance of AdiosNYBean */
public AdiosNYBean() {
}

}





The POJO trying to get the Context:



/*
* TestAdios.java
*
* Created on May 26, 2007, 4:27 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package ejb;
import java.util.Properties;
import javax.naming.InitialContext;
/**
*
* @author HANDAL
*/
public class TestAdios {


/** Creates a new instance of TestAdios */
public TestAdios() {
}
public static void main(String [] args)throws Exception{
Properties props=new Properties();

props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state","com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
InitialContext ic=new InitialContext(props);
AdiosNYRemote ad=(AdiosNYRemote)ic.lookup("Alpha");


}

}






init:
deps-jar:
compile-single:
run-main:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.(InitialContext.java:197)
at ejb.TestAdios.main(TestAdios.java:31)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)


 
Juan Handal
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dario I'm using netbeans 5.5.1 & java 6.

This is the error log:

init:
deps-jar:
compile-single:
run-main:
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.InitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.InitContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at ejb.TestAdios.main(TestAdios.java:26)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.InitContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 4 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

I've got tis information:

If you want to use a no-arg InitialContexr()

you need to put a "jndi.properties" file in your app client.

In my server GlassFish that file is empty.

(jndi.properties is inside $glassfish.home/lib/appserv-rt.jar)

I'm trying to set the jndi properties inside appserv-rt.jar so them

will be picked up.........


Application Server > Resources > JNDI > Custom Resources > Beta

Edit Custom Resource
Edit an existing JNDI custom resource.

Indicates required field
JNDI Name:Alpha

A unique identifier; contain only alphanumeric, underscore, dash, or dot characters
Resource Type:

Enter a fully qualified type; Resource Type definition follows the format xxx.xxx
Factory Class:

Factory class for resource; implements javax.naming.spi.ObjectFactory
Description:
Status: Enabled



Additional Properties (0)
Name Value
No properties found. Click "Add Property" above to add a property.


Finally

This is an EJB proyect(not WEB component)

src/Source Packages/ejb

In ejb packeges there is the SessionBean ,the remote interface(I tried

the local interface also) and the POJO wlth the main(String [] args){

trying ic.lookup(("Alpha")

The problem is that maybe netbeans is already setup for the InitialContext and not allow POJOs to lookup()?

Thanks


reply
    Bookmark Topic Watch Topic
  • New Topic