Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:48:11+00:00 2026-06-15T17:48:11+00:00

I am trying to build a simpmle Hello world type EJB 2.1 application. The

  • 0

I am trying to build a simpmle Hello world type EJB 2.1 application. The intended runtime for this application is supposed to be Jboss 5.1.0.
Here is the code i have written.

EJB Configuration file:

ejb/TestEJBInterfaceBean
com.TestEJB.TestEJBInterfaceHome
com.TestEJB.TestEJBInterfaceRemote
com.TestEJB.TestEJBInterfaceBean
Stateless
Container

Home interface:

import javax.ejb.EJBHome;

public interface TestEJBInterfaceHome extends EJBHome {
    public TestEJBInterfaceRemote create() throws java.rmi.RemoteException,
            javax.ejb.CreateException;
}

Remote Interface:

import java.rmi.RemoteException;
import javax.ejb.EJBObject;

public interface TestEJBInterfaceRemote extends EJBObject { 

    public String ping(String version) throws RemoteException;
}

Bean class:

import java.rmi.RemoteException;
import java.util.Date;

import org.jboss.logging.Logger;

public class TestEJBIInterfaceBean extends BaseSessionBean implements TestEJBIInterfaceRemote{

    private static final long serialVersionUID = 1L;

    final Logger log = Logger.getLogger(TestEJBIInterfaceBean.class);   


    public String ping(String arg0) throws RemoteException {

        String response = this.getClass().getSimpleName() + " pinged @ " + new Date().getTime();

        log.info(response);
        return response;
    }

    public void ejbActivate() throws EJBException, RemoteException {
        // TODO Auto-generated method stub

    }

    public void ejbPassivate() throws EJBException, RemoteException {
        // TODO Auto-generated method stub

    }

    public void ejbRemove() throws EJBException, RemoteException {
        // TODO Auto-generated method stub

    }

    public void setSessionContext(SessionContext arg0) throws EJBException,
            RemoteException {
        // TODO Auto-generated method stub

    }

    public EJBHome getEJBHome() throws RemoteException {
        // TODO Auto-generated method stub
        return null;
    }

    public Handle getHandle() throws RemoteException {
        // TODO Auto-generated method stub
        return null;
    }

    public Object getPrimaryKey() throws RemoteException {
        // TODO Auto-generated method stub
        return null;
    }

    public boolean isIdentical(EJBObject arg0) throws RemoteException {
        // TODO Auto-generated method stub
        return false;
    }

    public void remove() throws RemoteException, RemoveException {
        // TODO Auto-generated method stub

    }

}

The Test Client:

public class TestEJBInterfaceClientTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            Context ctx = new InitialContext();

            TestEJBInterfaceRemote obj = (TestEJBInterfaceRemote)ctx.lookup("ejb/TestEJBInterfaceBean");

            System.out.println(obj.ping("12345"));

        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
    }
}

When i run the client i get the following error:

Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to com.TestEJB.TestEJBInterfaceRemote
    at TestEJBInterfaceClientTest.main(TestEJBInterfaceClientTest.java:21)

The error seems to suggest that the cast is wrong but i suspect that the casting has nothing to do with the error. (i tried to cast to TestEJBInterfaceHome but i get the same error). My suspisions are actually in the version of the application.

Questions

  • Is there any possibility that Jboss is treating this as an EJB3 application? Looking at the configuration file i am not specifying that this is an EJB2.1 so maybe that is causing a problem?
  • Is there any way to find out what Type is returned from the ctx.lookup call? i tried getClass().getName, getClass().getCanonicalName() and all i get back is names like $proxy0, $proxy20 etc.
  • Have i missed something obvious?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:48:13+00:00Added an answer on June 15, 2026 at 5:48 pm

    The result of a pre-EJB-3.0 lookup is the home interface, so try casting to TestEJBInterfaceHome instead. Note that for portability, you need to use PortableRemoteObject.narrow on the return value of ctx.lookup before casting to the target interface.

    The actual type is a proxy class, so getClass().getName() is returning the correct thing. To determine what interfaces are implemented by the class, use getClass().getInterfaces().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to deploy my simple Qt project like a hello world. I build
Trying to build a simple helloWorld android/java application with jni c code. I am
It's getting frustrating. I've been trying to get a simple hello world type program
I'm trying to compile a simple hello world application to be run on uCLinux
Hello dearest community, I am trying to build a simple AutoUpdate application using VB.NET.
I'm trying to build a simple Maps app based on the hello map tutorial
i am trying to build simple php crawler for this purpose i am getting
I'm trying to build a simple HTML text editor in a Windows Form application.
I just installed and tried to build a simple Hello world program, however I
I'm a beginner in programming and I'm trying to build a simple application to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.