Hi all,
I'm nothing like sure this is a JBoss problem, but if it's not then I figure
someone here will probably have some sort of clue as to what's going on.
I have a client which looks like this:
import javax.naming.*;
import javax.ejb.*;
import au.com.asc.ejb.unit.*;
import java.util.*;
import java.net.*;
public class UnitTest
{
public static void main( String args[] )
{
try
{
for( int i = 0; i < args.length; i++ )
{
if( args[i].equals( "jndi" ) )
{
System.out.println
( Thread.currentThread().getContextClassLoader()
.getResource( "jndi.properties" ).toString() );
System.out.println
( Thread.currentThread().getContextClassLoader()
.getResource( "au/com/asc/ejb/unit/UnitHome.class"
).toString() );
Class c = Thread.currentThread().getContextClassLoader()
.loadClass( "au.com.asc.ejb.unit.UnitHome" );
System.out.println( c.getName() );
System.out.println(
Thread.currentThread().getContextClassLoader() );
System.out.println
( System.getProperty
( "java.naming.factory.initial" ) );
System.out.println
( System.getProperty( "java.naming.provider.url" ) );
}
if( args[i].equals( "rmicp" ) )
{
System.out.println
( "Adding RMI class loader." );
i++;
String rmicp = args[i];
URL[] clurls = new URL[] { new URL( rmicp ) };
ClassLoader rmicl = new URLClassLoader( clurls );
Thread.currentThread().setContextClassLoader( rmicl );
}
}
InitialContext ctx = new InitialContext();
Object o = ctx.lookup( "Unit" );
System.out.println( o.getClass().getClassLoader().toString() );
System.out.println(
Thread.currentThread().getContextClassLoader().toString() );
UnitHome h = (UnitHome)o;
Collection c = h.findByNameFragment( args[0] );
Iterator i = c.iterator();
while( i.hasNext() )
{
Unit u = (Unit)i.next();
System.out.println( u.getUDCName() );
}
}
catch( Throwable t )
{
t.printStackTrace();
}
}
}
and I run it with this command-line:
java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
-Djava.naming.provider.url=localhost UnitTest rmicp http://localhost:8083/ jndi
If you follow it through, that should make it set the context class loader to a
URLClassLoader with the url of http://localhost:8083/. It appears to do this.
It should then look for jndi.properties and au/com/asc/ejb/unit/UnitHome.class.
It finds both of these. It should then attempt to load the class
au.com.asc.ejb.unit.UnitHome (I've tried it with '/' instead of '.' also, it
doesn't make any difference). It should then report what the current
classloader is, as well as a couple of naming properties. It achieves all this
with no hassles.
It then does a JNDI lookup, which doesn't give it hassles, then it reports
which classloader it used the load 'java.lang.Object' and what the current
classloader is. Then it tries to cast the object to UnitHome. It's the cast
that kills it; it gives a NoClassDefFoundError.
All three classloader reports print the same thing. There's no problem with
mixing up which classloader is being used.
Why is it doing this?
If it's at all related, java.naming.provider.url is ignored, both in
jndi.properties and on the command line, and 127.0.0.1 is used instead.
I'm using JBoss built from the CVS snapshot of Jan. 19 2001.
Tom
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]