[jboss-user] [EJB/JBoss] - ClassLoader Mess Up

wecucho do-not-reply at jboss.com
Mon Sep 15 11:13:44 EDT 2008


Hi everyone, im having problems calling Bean from diferent projects, first of all, im using JBoss 4.2.2, i have prepared a simple project to test this particular issue.

The problem: i have 2 EARs (like most people... :P ), in each EAR i have configure a simple project with only one bean an one method, in project1.ear i have one bean named Saluted with this code:


  | package org.gilthanas.project1.bean;
  | 
  | import javax.ejb.Stateless;
  | import javax.naming.InitialContext;
  | 
  | import org.jboss.ejb3.JBossProxy;
  | 
  | /**
  |  * Author: cucho
  |  * Created on: Sep 15, 2008
  |  **/
  | @Stateless
  | public class SaluteBean implements Salute {
  | 
  | 	public void getSalute() {
  | 
  | 		System.out.println("Salute from project 1");
  | 		
  | 	}
  | 
  | 	public void callProject2() {
  | 		
  | 		try {
  | 			
  | 			InitialContext ctx = new InitialContext();
  | 			JBossProxy proxy = (JBossProxy) ctx.lookup("project2/SaluteBean/remote");
  | 			proxy.getAsynchronousProxy();
  | 			
  | 		} catch (Exception e) {
  | 			e.printStackTrace();
  | 		}
  | 		
  | 	}
  | 	
  | }
  | 

in project 2 i have this bean:

  | package org.gilthanas.project2.bean;
  | 
  | import javax.ejb.Stateless;
  | 
  | /**
  |  * Author: cucho
  |  * Created on: Sep 15, 2008
  |  **/
  | @Stateless
  | public class SaluteBean implements Salute {
  | 
  | 	public void getSalute() {
  | 		System.out.println("Salute from project 2");
  | 	}
  | 	
  | }
  | 

note the diference of the packages!!

so, inside my projet1.ear and project2.ear i have a jar file with only two classes Salute and SaluteBean (from package project1 for the project1 and package project2 for project2, don get confused! all its very carefull ordered), and the following application.xml:


  | <?xml version="1.0" ?>
  | <application>
  | 
  | 	<display-name>Some Name</display-name>
  |      
  | 	<module>
  | 		<ejb>project.jar</ejb>
  | 	</module>
  | 	
  |     <library-directory>lib</library-directory>
  |     
  | </application>
  | 

So, when i run my jboss and i deploy the two EARs (i lost my listen capability :P ...) all deploy goes just fine, and i can call my beans from a client like this running in my eclipse outside the jboss:


  | package org.gilthanas.project1.test;
  | 
  | import javax.naming.InitialContext;
  | 
  | import org.gilthanas.project1.bean.Salute;
  | 
  | /**
  |  * Author: cucho
  |  * Created on: Sep 15, 2008
  |  **/
  | public class TestP1 {
  | 
  | 	public TestP1() {
  | 		run();
  | 	}
  | 	
  | 	private void run() {
  | 		
  | 		try {
  | 			
  | 			InitialContext ctx = new InitialContext();
  | 			Salute salute = (Salute) ctx.lookup("project1/SaluteBean/remote");
  | 			salute.getSalute();
  | 			
  | 			
  | 		} catch (Exception e) {
  | 			e.printStackTrace();
  | 		}
  | 		
  | 	}
  | 	
  | 	public static void main(String[] args) {
  | 		new TestP1();
  | 	}
  | 
  | }
  | 

and when i call the two projects (calling the getSalute methods of each one) i get an output like this:

anonymous wrote : 
  | 2008-09-15 10:04:55,961 INFO  [STDOUT] Salute from project 1
  | 2008-09-15 10:05:00,645 INFO  [STDOUT] Salute from project 2
  | 

But, what happend when i try to call the method ' callProjet2 ' from project1 ? ERROR..

when i try to reach the project2 from project1 i get an error like this:
anonymous wrote : 
  | 2008-09-15 10:05:13,079 ERROR [STDERR] java.lang.IllegalArgumentException: interface org.gilthanas.project2.bean.Salute is not visible from class loader
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessRemoteProxy.getAsynchronousProxy(StatelessRemoteProxy.java:119)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at org.jboss.ejb3.ProxyUtils.handleCallLocally(ProxyUtils.java:148)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:83)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at $Proxy104.getAsynchronousProxy(Unknown Source)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at org.gilthanas.project1.bean.SaluteBean.callProject2(SaluteBean.java:27)
  | 2008-09-15 10:05:13,079 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,080 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:304)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:769)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:573)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:373)
  | 2008-09-15 10:05:13,081 ERROR [STDERR]  at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
  | 

That correspond to the line in org.gilthanas.project1.SaluteBean:

anonymous wrote : 
  | proxy.getAsynchronousProxy();
  | 

So, until i know... when i perform the lookup from project1 to reach project2 i get a instance of JBossProxy who has inside my real object (SaluteBean from project2) but when i try to reah the object apparently the class loader dont have the interface to perfom the cast...

i dont understand why, each EAR have a lib directory and is specified in the application.xml, so, the project1.ear have a lib with project2-client.jar (who has the remote class) and the project2.ear has a lib directory woth project1-client.jar..

i also do a test, copying the clients files (project1-client.jar and project2-client.jar) inside the client folder of the jboss and the lib folder of the server mode im using:

anonymous wrote : 
  | Into: 
  | /opt/jboss-4.2.2.GA/client
  | /opt/jboss-4.2.2.GA/server/all/lib
  | 


And is the same, he still saying that he does not have the classes... Anyone knows why or have some ideas ? 

NOTE: im using:

  | <attribute name="Isolated">true</attribute> 
  | 
in my ear-deployer.xml because in the future im gonna have a lot of EARs (i will listen again :) ) with independent beans but the same classes, i dont want instances getting mixed.

Thanks in advance!

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4176557#4176557

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4176557



More information about the jboss-user mailing list