Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in deploying ejb3 app in jboss server

 
anil gowda
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
anil gowda
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its working fine now. Error was because of a jar file i missed to add in classpath.

Thank you,
Anil
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic