Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Some body tells me where did i do wrong?

  Asked By: James    Date: Jul 14    Category: Java    Views: 784
  

I've been trying to release an easy program in EJB3 please some one
tells me where did i do wrong. I've tried to explain all steps with
all details.

First Step:

public interface Hello { public void sayHello(); }
-------------------------------------------------------
Second Step:

import javax.ejb.*;

@Stateless
@Remote(Hello.class)

public class HelloBean implements Hello {
public void sayHello() {
System.out.println("Hello");
}
}
--------------------------------------------------------
Third Step:

I created META-INF folder behind my two objects that i've created + MANIFEST.MF
--------------------------------------------------------

Fourth Step:

/META-INF/Ejb-jar.xml file

<?xml version="1.0" encoding="UTF-8" ?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_3_0.xsd"
version="3.0">
<enterprise-beans>
</enterprise-beans>
</ejb-jar>
--------------------------------------------------------------------------------

Fifth Step:

/META-INF/jboss.xml file

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<jndi-name>HelloJndi</jndi-name>
</session>
</enterprise-beans>
</jboss>
--------------------------------------------------------------------------------\
---

Sixth Step:

I compiled my java files without any exception or error and after that
i created my component and i named it test.jar without any exception
or error message too.
--------------------------------------------------------------------------------\
---

Seventh Step

i copied my component (test.jar) in to my ejb container for deploying.

/usr/share/jboss-4.2.1.GA/server/default/deploy/ejb3.deployer/test.jar----------\
--------->
my component path
i started my Web Server and my component was deployed without any
exception or any error messages.
--------------------------------------------------------------------------------\
-------------------------------------------------

Eighth Setpe:

i think my problem is here, My JNDI file and handling my jboss properties.

import javax.naming.*;
import java.util.Properties;

public class HelloJndi {
public static void main(String[] m) throws Exception {
Properties prop = new Properties();

prop.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContext\
Factory");

prop.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interf\
aces");
prop.setProperty("java.naming.provider.url","localhost:");

Context cnt = new InitialContext(prop);
Hello hello = (Hello) cnt.lookup("Hello");
hell.sayHello();
}
}

this file compiled without any exception or any error messages. BUT
when i run this file i encounter


Exception in thread "main" 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(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 HelloJndi.main(HelloJndi.java:12)
Caused by: java.lang.ClassNotFoundException:
org.jnp.interfaces.NamingContextFactory
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

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Chau Tran     Answered On: Jul 14

where is this client code running?
it looks like ther naming  context is not available in the container
you are running your client code.

 
Answer #2    Answered By: Viheke Fischer     Answered On: Jul 14

According to 'ClassNotFoundException', I think you've forget to place
'jbossall-client.jar' in the classpath of client. Give it a try.

By the way, why don't you pass rmi-registry port number? e.g. 1099 :)

 
Answer #3    Answered By: Jeanette Greene     Answered On: Jul 14

the exception  is clear
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory

it complains that class  is not loaded, you have to add the appropriate jar  file

apart from that, while setting your properties  at line: prop.setProperty("java.naming.provider.url","localhost:");
you must remove the : (colon) from the value

 
Didn't find what you were looking for? Find more on Some body tells me where did i do wrong? Or get search suggestion and latest updates.




Tagged: