• 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

problem in deploying ejb3 app in jboss server

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.naming:org.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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic