you can't look the ejbs up with JNDI?
I can look up EJB via JNDI by using jbossall-client.jar, but the problem is when I inlcude this paritcular jar in web-inf/lib in the war file from inside web container, JBOSS 4.2.1.GA failed to deploy the war file with some "java.lang.IncompatibleClassChangeError" log infomation. the whole war deployment stopped after a successful EJB call (ejb call succeeded with good data back).
the jbossall-client.jar is for use in an external client. you're probably getting that error because jboss has already loaded the class and you're trying to load it again.
what exactly are you using that jboss doesn't provide by default?
yes, you are right, when I use jbossall-client.jar in an external client, it is fine. actually I need to use some EJB lookup-specific jar/jars (e.g. jnp-client.jar, jboss-je22.jar, etc.) within my web application. I tried to use some other jars combination instead of use the big jbossall-client.jar, but it ended up giving me the same error especially if I use jnp-client.jar.
I thought the default classloading sequence for a web application is web libraries first, then tomcat libraries and jboss libraries. So before my war is deployed, everything is fine with JBoss, when JBOSS is trying to deploy my war file in a isolated web application scope, it gets jbossall-client.jar loaded first, which might contains some implementation classes with different version of dependencies classes from server side version of dependencies classes I guess. then there is conflicts. That's my thoughts about the issue, but I don't how to fix it.
can you be more specific about what you're using in jnp-client.jar, etc..
you shouldn't need to use those within your web application.
I use JBOSS "jnp://ip:1099" as Context.PROVIDER_URL to look up EJB remote instance and with "org.jboss.naming:org.jnp.interfaces" for env setting of "java.naming.factory.url.pkgs", that's why I need jnp-client.jar, which is also included in jbossall-client.jar.
If I don't use these jars, how to look up EJB remote instance by ejb jndi name. Is there any other protocol or setting that can be used for looking up EJB from JBOSS application server container? what's your idea?
fortunately you don't need the jnp-client.jar to do that. try this:
Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "192.168.bl.ah:1099"); Context ctx = new InitialContext(p); MyRemote bean = (MyRemote)ctx.lookup("the jndi name");
if you are looking up a bean from the same server, then you can just do:
Context ctx = new InitialContext(); MyRemote bean = (MyRemote)ctx.lookup("the jndi name");
Is that becasuse I am using Context.INITIAL_CONTEXT_FACTORY with vaule of "org.jboss.security.jndi.JndiLoginInitialContextFactory", so if I dropped off jbossall-client.jar (including the classes from jnp-client.jar), it gave me error like the following:
javax.ejb.CreateException,java.rmi.RemoteException javax.ejb.EJBException: Invalid invocation, check your deployment packaging .......
Also, just as you suggested, I removed Context.PROVIDER_URL setting for InitialContext's parameter 'coz it's looking up EJB from inside the server, and the codes arejust like the following:
Properties env1 = new Properties();
Context initial = new InitialContext(env1);
it still gave me error like:
Caused by: java.lang.ClassCastException: $Proxy83
could you post the code used to do the lookup and the casting of the returned object?
Properties env = new Properties();
Context initial = new InitialContext(env);
Object objref = initial.lookup(jndiName);
MyEjbHome home = (MyEjbHome) PortableRemoteObject.narrow(objref, EjbHomeClass);
Object MyEjbRemote= home.create();
is EjbHomeClass the same as MyEjbHome.class?
yes, EjbHomeClass is the same as MyEjbHome.class