Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes problem in deploying ejb3 app in jboss server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "problem in deploying ejb3 app in jboss server" Watch "problem in deploying ejb3 app in jboss server" New topic
Author

problem in deploying ejb3 app in jboss server

anil gowda
Greenhorn

Joined: Jun 12, 2007
Posts: 12
Hello All!

I'm trying to develop a sample application using EJB3.

application has been deployed successfully...no problem with that.

But, when i try to call bean from my client code im getting following exception.


Exception in thread "main" java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.kalki.session.MyBeanRemote
at com.kalki.session.MyBeanclient.main(MyBeanclient.java:28)


Here's is my complete code.

Super interface--->IMyBean

package com.kalki.session;

import java.io.Serializable;

public interface IMyBean extends Serializable{

public void show();


}

---------------------------------
Remote Interface----->>MyBeanRemote

package com.kalki.session;

import javax.ejb.Remote;

@Remote
public interface MyBeanRemote extends IMyBean{

}

---------------------------------------
Local Interface--->MyBeanLocal

package com.kalki.session;

import javax.ejb.Local;

@Local
public interface MyBeanLocal extends IMyBean{

}

--------------------------------------------
Session Bean---MyBean

package com.kalki.session;

import javax.ejb.Stateless;

@Stateless
public class MyBean implements MyBeanLocal, MyBeanRemote {



public void show()
{
System.out.println("Hi how are you");
}


}

----------------------------------------------
Client Class---->MyBeanclient

package com.kalki.session;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class MyBeanclient {

/**
* @param args
*/
public static void main(String[] args) {
try {




Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.namingrg.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context context;

context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();

} catch (NamingException e) {
e.printStackTrace();
}

}

}

I googled for solution but it is of no help.

Please help me.

Thanks in advance,
Anil
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Which version of JBoss AS? And do you have the jbossall-client.jar (and the jars it references in it's MANIFEST.MF) in the client classpath?

[My Blog] [JavaRanch Journal]
anil gowda
Greenhorn

Joined: Jun 12, 2007
Posts: 12
Hi jaikiran,

I am using Myeclipse IDE, im deploying the app in jboss-5.0.1.GA and i have added jbossall-client.jar to the build path.
As i said in my previous post that the app is getting deployed but when i run the client program im getting the exception.

Am i missing to add any other jar files?? Can you please list out the jars i should add to build path.

Thanks in advance,
Anil

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

How do you run your client? From the IDE? I usually stay away from IDEs for building/running my apps, so i won't be able to help much around that.

Can you please list out the jars i should add to build path.


The client classpath should have the jbossall-client.jar and the other jars that are listed in the MANIFEST.MF of the jbossall-client.jar.
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
you are wrong at this point:
context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();


it should be:


context = new InitialContext(properties);
Object bean = (Object)context .lookup("MyBean/remote");
MyBeanRemote remoteBean=(MyBeanRemote)PortableRemoteObject.narrow(bean,MyBeanRemote.class)
bean.show();


Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

pankaj vijay wrote:you are wrong at this point:
context = new InitialContext(properties);
MyBeanRemote bean = (MyBeanRemote)context .lookup("MyBean/remote");
bean.show();


it should be:


context = new InitialContext(properties);
Object bean = (Object)context .lookup("MyBean/remote");
MyBeanRemote remoteBean=(MyBeanRemote)PortableRemoteObject.narrow(bean,MyBeanRemote.class)
bean.show();



The PortableRemoteObject.narrow is actually not required in EJB3. What Anil posted should work after he fixes the client classpath.
pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
The PortableRemoteObject.narrow is actually not required in EJB3. What Anil posted should work after he fixes the client classpath.


Yes it is not mandatory but if you will not use it... then probably it will not work on RMI.
anil gowda
Greenhorn

Joined: Jun 12, 2007
Posts: 12
Its working fine now. Error was because of a jar file i missed to add in classpath.

Thank you,
Anil
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: problem in deploying ejb3 app in jboss server