X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 09 May 2007 03:09 PM by  anon
Java Class.forName() Problem
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
09 May 2007 03:09 PM
    Hi I'm experimenting with the IDL-Java bridge but I'm having problems with Class.forName() - it throws a ClassNotFoundException always. In the default IDL configuration I can run the urlread.pro example no problem, so the JVM Classpath seems OK. However, if I then construct a java.lang.Class object and invoke: jClass->forName, 'URLReader' it fails with a ClassNotFoundException. Any ideas please? James

    Deleted User



    New Member


    Posts:
    New Member


    --
    09 May 2007 03:09 PM
    James, I worry a little about this statement from the Java API documentation for class Class: "Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader." So, what calling syntax are you using to "construct a java.lang.Class Object" in your IDL code? I.e., how are you instantiating this 'jClass' object? James Jones

    Deleted User



    New Member


    Posts:
    New Member


    --
    17 May 2007 06:19 AM
    For anyone who's interested, I found a solution that works for me. It seems that Class.forName() is not using the correct ClassLoader, specifically not a ClassLoader that uses the classpath. This is explained here: http://www.theserverside....sForname/DynLoad.pdf The short version of the solution, without all the usual housekeeping and error catching, is as follows: jClass = obj_new('IDLjavaObject$Static$JAVA_LANG_CLASS', 'java.lang.Class') jClassLoader = obj_new('IDLjavaObject$Static$JAVA_LANG_CLASSLOADER', 'java.lang.ClassLoader') jSystemClassLoader = jClassLoader->getSystemClassLoader() jClass->forName, 'ClassName', 0, jSystemClassLoader Hardly the epitome of elegance but it does work regards James
    You are not authorized to post a reply.