Loading jar files at execution time via URLClassLoader

Hello�All,
I'm�making�a�Java�SQL�Client.�I�have�practicaly�all�basic�work�done,�now�I'm�trying�to�improve�it.
One�thing�I�want�it�to�do�is�to�allow�the�user�to�specify�new�drivers�and�to�use�them�to�make�new�connections.�To�do�this�I�have�this�class:�
public�class�DriverFinder�extends�URLClassLoader{
����private�JarFile�jarFile�=�null;
����
����private�Vector�drivers�=�new�Vector();
����
����public�DriverFinder(String�jarName)�throws�Exception{
��������super(new�URL[]{�new�URL("jar",�"",�"file:"�+�new�File(jarName).getAbsolutePath()�+"!/")�},�ClassLoader.getSystemClassLoader());
��������jarFile�=�new�JarFile(new�File(jarName));
��������
��������/*
��������System.out.println("-->"�+�System.getProperty("java.class.path"));
��������System.setProperty("java.class.path",�System.getProperty("java.class.path")+File.pathSeparator+jarName);
��������System.out.println("-->"�+�System.getProperty("java.class.path"));
��������*/
��������
��������Enumeration�enumeration�=�jarFile.entries();
��������while(enumeration.hasMoreElements()){
������������String�className�=�((ZipEntry)enumeration.nextElement()).getName();
������������if(className.endsWith(".class")){
����������������className�=�className.substring(0,�className.length()-6);
����������������if(className.indexOf("Driver")!=-1)System.out.println(className);
����������������
����������������try{
��������������������Class�classe�=�loadClass(className,�true);
��������������������Class[]�interfaces�=�classe.getInterfaces();
��������������������for(int�i=0;�i<interfaces.length;�i++){
������������������������if(interfaces.getName().equals("java.sql.Driver")){
����������������������������drivers.add(classe);
������������������������}
��������������������}
��������������������Class�superclasse�=�classe.getSuperclass();
��������������������interfaces�=�superclasse.getInterfaces();
��������������������for(int�i=0;�i<interfaces.length;�i++){
������������������������if(interfaces[i].getName().equals("java.sql.Driver")){
����������������������������drivers.add(classe);
������������������������}
��������������������}
����������������}catch(NoClassDefFoundError�e){
����������������}catch(Exception�e){}
������������}
��������}
����}
����
����public�Enumeration�getDrivers(){
��������return�drivers.elements();
����}
����
����public�String�getJarFileName(){
��������return�jarFile.getName();
����}
����
����public�static�void�main(String[]�args)�throws�Exception{
��������DriverFinder�df�=�new�DriverFinder("D:/Classes/db2java.zip");
��������System.out.println("jar:�"�+�df.getJarFileName());
��������Enumeration�enumeration�=�df.getDrivers();
��������while(enumeration.hasMoreElements()){
������������Class�classe�=�(Class)enumeration.nextElement();
������������System.out.println(classe.getName());
��������}
����}
It�loads�a�jar�and�searches�it�looking�for�drivers�(classes�implementing�directly�or�indirectly�interface�java.sql.Driver)�At�the�end�of�the�execution�I�have�found�all�drivers�in�the�jar�file.
The�main�application�loads�jar�files�from�an�XML�file�and�instantiates�one�DriverFinder�for�each�jar�file.�The�problem�is�at�execution�time,�it�finds�the�drivers�and�i�think�loads�it�by�issuing�this�statement�(Class�classe�=�loadClass(className,�true);),�but�what�i�think�is�not�what�is�happening...�the�execution�of�my�code�throws�this�exception
java.lang.ClassNotFoundException:�com.ibm.as400.access.AS400JDBCDriver
��������at�java.net.URLClassLoader$1.run(URLClassLoader.java:198)
��������at�java.security.AccessController.doPrivileged(Native�Method)
��������at�java.net.URLClassLoader.findClass(URLClassLoader.java:186)
��������at�java.lang.ClassLoader.loadClass(ClassLoader.java:299)
��������at�sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
��������at�java.lang.ClassLoader.loadClass(ClassLoader.java:255)
��������at�java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
��������at�java.lang.Class.forName0(Native�Method)
��������at�java.lang.Class.forName(Class.java:140)
��������at�com.marmots.database.DB.<init>(DB.java:44)
��������at�com.marmots.dbreplicator.DBReplicatorConfigHelper.carregaConfiguracio(DBReplicatorConfigHelper.java:296)
��������at�com.marmots.dbreplicator.DBReplicatorConfigHelper.<init>(DBReplicatorConfigHelper.java:74)
��������at�com.marmots.dbreplicator.DBReplicatorAdmin.<init>(DBReplicatorAdmin.java:115)
��������at�com.marmots.dbreplicator.DBReplicatorAdmin.main(DBReplicatorAdmin.java:93)
Driver�file�is�not�in�the�classpath�!!!�
I�have�tried�also�(as�you�can�see�in�comented�lines)�to�update�System�property�java.class.path�by�adding�the�path�to�the�jar�but�neither...
I'm�sure�I'm�making�a/some�mistake/s...�can�you�help�me?
Thanks�in�advice,
(if�there�is�some�incorrect�word�or�expression�excuse�me)

Sorry i have tried to format the code, but it has changed   to �... sorry read this one...
Hello All,
I'm making a Java SQL Client. I have practicaly all basic work done, now I'm trying to improve it.
One thing I want it to do is to allow the user to specify new drivers and to use them to make new connections. To do this I have this class:
public class DriverFinder extends URLClassLoader{
private JarFile jarFile = null;
private Vector drivers = new Vector();
public DriverFinder(String jarName) throws Exception{
super(new URL[]{ new URL("jar", "", "file:" + new File(jarName).getAbsolutePath() +"!/") }, ClassLoader.getSystemClassLoader());
jarFile = new JarFile(new File(jarName));
System.out.println("-->" + System.getProperty("java.class.path"));
System.setProperty("java.class.path", System.getProperty("java.class.path")+File.pathSeparator+jarName);
System.out.println("-->" + System.getProperty("java.class.path"));
Enumeration enumeration = jarFile.entries();
while(enumeration.hasMoreElements()){
String className = ((ZipEntry)enumeration.nextElement()).getName();
if(className.endsWith(".class")){
className = className.substring(0, className.length()-6);
if(className.indexOf("Driver")!=-1)System.out.println(className);
try{
Class classe = loadClass(className, true);
Class[] interfaces = classe.getInterfaces();
for(int i=0; i<interfaces.length; i++){
if(interfaces.getName().equals("java.sql.Driver")){
drivers.add(classe);
Class superclasse = classe.getSuperclass();
interfaces = superclasse.getInterfaces();
for(int i=0; i<interfaces.length; i++){
if(interfaces[i].getName().equals("java.sql.Driver")){
drivers.add(classe);
}catch(NoClassDefFoundError e){
}catch(Exception e){}
public Enumeration getDrivers(){
return drivers.elements();
public String getJarFileName(){
return jarFile.getName();
public static void main(String[] args) throws Exception{
DriverFinder df = new DriverFinder("D:/Classes/db2java.zip");
System.out.println("jar: " + df.getJarFileName());
Enumeration enumeration = df.getDrivers();
while(enumeration.hasMoreElements()){
Class classe = (Class)enumeration.nextElement();
System.out.println(classe.getName());
It loads a jar and searches it looking for drivers (classes implementing directly or indirectly interface java.sql.Driver) At the end of the execution I have found all drivers in the jar file.
The main application loads jar files from an XML file and instantiates one DriverFinder for each jar file. The problem is at execution time, it finds the drivers and i think loads it by issuing this statement (Class classe = loadClass(className, true);), but what i think is not what is happening... the execution of my code throws this exception
java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at com.marmots.database.DB.<init>(DB.java:44)
at com.marmots.dbreplicator.DBReplicatorConfigHelper.carregaConfiguracio(DBReplicatorConfigHelper.java:296)
at com.marmots.dbreplicator.DBReplicatorConfigHelper.<init>(DBReplicatorConfigHelper.java:74)
at com.marmots.dbreplicator.DBReplicatorAdmin.<init>(DBReplicatorAdmin.java:115)
at com.marmots.dbreplicator.DBReplicatorAdmin.main(DBReplicatorAdmin.java:93)
Driver file is not in the classpath !!!
I have tried also (as you can see in comented lines) to update System property java.class.path by adding the path to the jar but neither...
I'm sure I'm making a/some mistake/s... can you help me?
Thanks in advice,
(if there is some incorrect word or expression excuse me)

Similar Messages

  • How to dynamically load jar files - limiting scope to that thread

    Dynamically loading jar files has been discussed a lot. I have read a quite a few posts, articles, and demo code for doing just that. However, I have yet to find a solution to my problem. Most people modify their system class loader and are happy. I have done that and was happy for a time. Occasionally, you will see reference to an application server or tomcat or some other large project that have successfully been able to load and unload jar files, allow for dynamic deployment of code, etc. However, I have not been able to achieve similar success; And my problem is much less complicated.
    I have an application that executes a thread to send a given file/message to a standard JMS Server Queue. Depending on the parameters selected by the user, this thread may need to communicate with one of a number of JMS Servers, ie. JBoss, WebLogic, EAServer, Glassfish, etc. All of which can be done with the same code, but each needs to load their own flavor of JMS Client Jar files. In this instance, spawning a separate JVM for each communication would work from a classloader perspective. However, I need to keep it in the family and run under the same JVM, albeit each JMS Server Connection will be created and maintained in separate Threads.
    I am close, I am doing the following...
    1. Creating a new URLClassLoader in the run() method of each thread.
    2. Set this threads contextClassLoader to the new URLClassLoader.
    3. Load the javax.jms.JMSException class with the URLClassLoader.loadClass() method.
    4. Create an initialContext object within this thread.
    Note: I read that the initialContext and subsequent conext lookup calls would use the Thread�s
    contextClassLoader for finding/loading classes.
    5. Perform context.lookup calls for a connectionFactory and Queue name.
    6. Create JMS Connection, etc. Send Message.
    Most of this seems to work. However, I am still getting a NoClassDefFoundError exception for the javax.jms.JMSException class ( Note step #3 - tried to cure unsuccessfully).
    If I include one of the JMS Client jar files ( ie wljmsclient.jar for weblogic ) in the classpath then it works for all the different JMS Servers, but I do not have confidence that each of the providers implemented these classes that now resolve the same way. It may work for now, but, I believe I am just lucky.
    Can anyone shine some light on this for me and all the others who have wanted to dynamically load classes/jar files on a per Thread basis?

    Thanks to everyone - I got it working!
    First, BenSchulz' s dumpClassLoader() method helped me to visualize the classLoader hierarchy. I am still not completely sure I understand why my initial class was always found by the systemClassLoader, but knowning that - was the step I needed to find the solution.
    Second, kdgregory suggested that I use a "glue class". I thought that I already was using a "glue class" because I did not have any JMSClient specific classes exposed to the rest of the application. They were all handled by my QueueAdmin class. However...
    The real problem turned out to be that my two isolating classes (the parent "MessageSender", and the child "QueueAdmin") were contained within the same jar file that was included in the classpath. This meant that no matter what I did the classes were loaded by the systemClassLoader. Isolating them in classes was just the first step. I had to remove them from my jar file and create another jar file just for those JMSClient specific classes. Then this jar file was only included int custom classLoader that I created when I wanted to instantiate a JMSClient session.
    I had to create an interface in the primary jar file that could be loaded by the systemClassLoader to provide the stubs for the individual methods that I needed to call in the MessageSender/QueueAdmin Classes. These JMSClient specific classes had to implement the interface so as to provide a relationship between the systemClassLoader classes and the custom classLoader classes.
    Finally, when I loaded and instantiated the JMSClient specific classes with the custom classLoader I had to cast them to the interface class in order to make the method calls necessary to send the messages to the individual JMS Servers.
    psuedu code/concept ....
    Primary Jar File   -  Included in ClassPath                                                      
    Class<?> cls = ClassLoader.loadClass( "JMSClient.MessageSender" )
    JMSClientInterface jmsClient = (JMSClientInterface) cls.newInstance()                            
    jmsClient.sendMessage()                                                                      
    JMSClient Jar File  -  Loaded by Custom ClassLoader Only
    MessageSender impliments Primary.JMSClientInterface{
        sendMessage() {
            Class<?> cls=ClassLoader.loadClass( "JMSClient.QueueAdmin" )
            QueueAdmin queueAdmin=(QueueAdmin) cls.newInstance()
            queueAdmin.JMSClientSpecificMethod()
        }

  • How to load jar files from remote location

    Hi all,
    I am trying to load jar files from remote server, from a servlet which is running on OC4j.
    For doing this,First I am getting ClassLoader by using ClassLoader.getSystemClassLoader() and then type casting it to URLClassLoader.
    But by doing it I am getting ClassCastException,because oc4j returns oracle.classloader.PolicyClassLoader instead of java.net.ClassLoader.
    Appreciate if anyone can tell me how to load remote jar files using oracle.classloader.PolicyClassLoader .
    Thanks
    Harish

    Hi,
    I suppose you know about this, but just in case.
    I have used jnpl to load jar files from remote location.
    Rowan

  • Dynamically loading jar files

    Hi
    In my application I need to dynamically create objects of types specified by string which is passed as parameter. I am able to do this if the class is inside the same jar. But I need to load the class from any jar name specified. How do i go about doing this? Is there a way to dynamically loading jar files?

    It's easy. You use [url http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html]URLClassLoader:String jarPath = ...;
    String className = ...;
    URLClassLoader ucl = new URLClassLoader(new URL[] { new File(jarPath).toURL() });
    Class cls = Class.forName(className, true, ucl);
    ...Regards

  • Urgent. How may i update a properties file in execution time?

    Urgent, please. How may i update a properties file in execution time? I need to update the file by means of a web page and i need the changes be reflected immediately.
    Thanks

    Note the update must be made in memory. But i don�t know how.

  • How to load jar file in oracle 9i???

    Hi Friends,
    Can you help me, how to load jar file oracle 9i? I have to tried to load in 10g using loadjava command but it's not working in oracle 9i because the loadjava batch file itself is not there in oralce 9i.
    Is there any other way then pls let me know.
    - Hiren Modi

    Hi,
    I have oracle version : Release 2 (9.2.0.1.0) for Windows. I have tried to execute the loadjava command from SQL prompt but its giving as below.
    H:\>loadjava
    The system cannot find the path specified.
    Do you know why its giving error like this. I have checked in dir : C:\oracle\ora92\bin but loadjava executable file is not there in it.
    - Hiren Modi

  • Load jar file into Oracle db 10.1.0.2.0.

    Hi,
    I am trying to create a Java Stored procedure that is dependent on some other classes. The java source doesn't compile since it cannot find the imported libs.
    How can I load jar files into the database so I can get my java source to compile?
    I have heard of dbms_java.loadjava procedure, but not very clear on how to use it.
    Please let me know how I can load the jar files in to the db.
    Thanks,
    -- DR.

    http://oraclesvca2.oracle.com/docs/cd/B12037_01/java.101/b12021/dbms_jav.htm

  • Urgent: Does dbms_java package is required  to load jar file into database?

    Hi, It's a urgent request. I am trying to install jar file that was created by JDeveloper into database using loadjava. But it is giving so many errors.
    Do we need to install dbms_java package in order to load jar files into the database? Thanks.

    Thanks for your reply Kamal.
    I am trying to load these jar files into Oracle 9.2.0.3.20 database.
    Could you please give me the list of the steps to enable java within the database? Thanks.

  • Load jar file

    Hi
    I use EBS r12, i try to load jar file, i put it in $OA_JAVA/oracle/apps/fnd/jar and run adautocfg.sh, but the application not see the jar file?
    Is there any solution for that?
    Thanks

    Read from application developers guide for ebs developers about how to register jar files in oracle ebs. Also read these,
    Java and JAR in Oracle Apps
    http://www.exforsys.com/tutorials/oracle-apps/registering-new-forms-in-oracle-apps-11i.html
    http://www.aboutoracleapps.com/2009/01/how-to-register-shell-script-as.html

  • Load .JAR file using SQL Developer

    Hi,
    I have couple of .JAR files on my local machine which has to be loaded on to the oracle server (11g). I tried using the load Java functionality in the SQL Developer but realised one could load a java class only if you had the source code.
    Is my understanding correct or is there a way to load a JAR file using sql developer ?
    Thanks

    K,
    Thanks for the answer.
    Do you know if you have to restart oracle after loading .jar files ? I ask this because I am not aware if oracle/jvm automatically knows that the jar files have been uploaded.
    Thanks

  • How to load jar file using SQL Developer

    Dear All,
    I need urgent help to load mytest.jar to the database using SQL Developer. I am able to load individual java classes to the database using SQL developers, but i could not load JAR files. Please help me any one know how to do this using SQL Developer.
    Thanks and Regards
    John p

    I don't think that's possible, so load it through the OS with the loadjava utility.
    Have fun,
    K.

  • How to load jar file in one shot?

    I have a Java app refers some jar files on remote location. Loading class by class is very time consuming.
    Is it possible to load the jar files as a whole? like what applet does?
    Tried URLClass loading, even run java -jar, still those load class on demand.
    I want the jar file loaded only one time into JVM.

    I don't really understand. When you load a jar file using URLClassLoader it brings over the jar file and extracts the class files from the jar file. It does not bring over the class files as individual class files. If you mean you want to only ever bring over the jar file once then why not just copy the jar file using URLConnection and save it to disk. You can then load the jar file from disk each time the program starts.

  • Quick load jar files?

    I have an application that uses a bunch of .jar files (BIRT framework for eclipse). The first time I run this application I takes almost forever, but the second time it runs very fast. I assume its because all the jarfiles are loaded the first time. But is it possible to create a quick loader of some kind that loads the program before its actually run the first time?

    You have to make a URLClassloader that points to inside the JAR files. GThis question has come up several times in the past week, so a quick search will provide a couple of working solutions.
    Note that if you plan on calling methods from classes in the plugin jars, they should either implement an interface or extend an class that you know and can import during compile time, or provide some method of identifying what method needs to run and what that method's arguments are so that you can use reflection.
    I belive these things are also alluded to in the recent threads.
    (Keywords to search for: dynamic JARClassLoader plugins)

  • Java Applet fails loading JAR files

    I'm using the OC4J setup with my Oracle forms (10g) install, this was working but no longer.
    I get the message below when running the test.fmx from the Oracle Forms Services test page for each of the JAR files attempting to load.
    I comment out the ARCHIVE statement but it still fails with
    'java.lang.ClassNotFoundException:oracle.forms.engine.Main' on the applet window.
    =====================
    java.io.IOException: Connection failure with 504
         at sun.plugin.protocol.jdk12.http.HttpURLConnection.getInputStream(Unknown Source)
         at oracle.jre.protocol.jar.HttpUtils.followRedirects(Unknown Source)
         at oracle.jre.protocol.jar.JarCache$CachedJarLoader.isUpToDate(Unknown Source)
         at oracle.jre.protocol.jar.JarCache$CachedJarLoader.loadFromCache(Unknown Source)
         at oracle.jre.protocol.jar.JarCache$CachedJarLoader.load(Unknown Source)
         at oracle.jre.protocol.jar.JarCache.get(Unknown Source)
         at oracle.jre.protocol.jar.CachedJarURLConnection.connect(Unknown Source)
         at oracle.jre.protocol.jar.CachedJarURLConnection.getJarFile(Unknown Source)
         at sun.misc.URLClassPath$JarLoader.getJarFile(Unknown Source)
         at sun.misc.URLClassPath$JarLoader.<init>(Unknown Source)
         at sun.misc.URLClassPath$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.misc.URLClassPath.getLoader(Unknown Source)
         at sun.misc.URLClassPath.getLoader(Unknown Source)
         at sun.misc.URLClassPath.getResource(Unknown Source)
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at sun.plugin.security.PluginClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    WARNING: error reading http://nzmdgrenfell01.asiapacific.hpqcorp.net:8889/forms/java/frmwebutil.jar from JAR cache.
    Downloading http://nzmdgrenfell01.asiapacific.hpqcorp.net:8889/forms/java/frmwebutil.jar to JAR cache
    java.io.IOException: Connection failure with 504
    Any suggestions?
    Regards......Derek

    I found this Metalink that solved my problem.
    Note:171159.1

  • Trying to load jar file dynamically

    I'm trying to load the jar file dynamically and making the new instance of an objet present in it.
    mu source code -
    import java.net.*;
    import java.util.*;
    import java.io.*;
    import java.lang.reflect.Method;
    class A
    /** The class loader to use for loading JMeter classes. */
    private static URLClassLoader loader;
         static {
              System.out.println("classpath : " + System.getProperty("java.class.path"));
    URL[] urls = new URL[1];
    StringBuffer classpath = new StringBuffer();
    File f = new File("E:\\try\\lib\\dom4j.jar");
              String s = f.getPath();
    try
                   urls[0] = new URL("file", "", s);
              catch (MalformedURLException e)
                   e.printStackTrace();
    System.setProperty(
    "java.class.path",
    System.getProperty("java.class.path") + System.getProperty("path.separator") + s);
    loader = new URLClassLoader(urls);
    * Prevent instantiation.
    private A()
    * The main program which actually runs JMeter.
    * @param args the command line arguments
    public static void main(String[] args) throws Exception
              System.out.println("java,class.path : " + System.getProperty("java.class.path"));
    Thread.currentThread().setContextClassLoader(loader);
              System.out.println("loader : " + loader);
              System.out.println("java.class.path : " + System.getProperty("java.class.path"));
              System.out.println("classpath : " + System.getenv("classpath"));
    try
    Class B = loader.loadClass("B");
    Object instance = B.newInstance();
    Method startup =
    B.getMethod("print");
    startup.invoke(instance);
    catch (Exception e)
    e.printStackTrace();
    import org.dom4j.*;
    import org.dom4j.dom.*;
    import java.lang.reflect.*;
    class B
         public void print () throws Exception
              //Element e = DocumentHelper.createElement("hello");     
              //e.addText("sachin");     
              //System.out.println(e.asXML());
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
              System.out.println("loader : " + loader);
    Class c = loader.loadClass("org.dom4j.dom.DOMElement");
              //Class c = Class.forName("org.dom4j.dom.DOMElement");
              Constructor con = c.getConstructor(new String().getClass());
              DOMElement el = (DOMElement)con.newInstance(new String("asd"));
              //DOMElement dm = new DOMElement("ADD");
              System.out.println(el);
    the class org.dom4j.dom.DOMElement is present in the jar file .
    basically i'm getting an exception, given below--
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorI
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodA
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at A.main(A.java:59)
    Caused by: java.lang.NoClassDefFoundError: org/dom4j/dom/DOMElement
    at B.print(B.java:18)
    ... 5 more
    thanks alot..
    Regards,
    Sachin

    Alright let me tell you guys what I am doing. I am using reflection to load the class from a jar file. Then, I am accessing a method defined in the class.
    This piece of code will load and start the class;
    Class c = loadClass(name);
    System.out.println("name:" + name);
    System.out.println("c:" + c);
    Method m = c.getMethod("ServiceStarted", new Class[0]);
    d1 = c.newInstance();
    System.out.println("d1:" + d1);
    m.setAccessible(true);
    try {
    m.invoke(d1, new Object[0] );
    } catch (IllegalAccessException e) {
    This piece of code will invoke a preloaded class;
    String s = d1.getClass().getName();
    Class c = Class.forName(s);
    System.out.println(c);
    Object ret = null;
    Method m = c.getMethod("Hello", new Class[] { String.class });
    Object d = c.newInstance();
    m.setAccessible(true);
    try {
    ret = m.invoke(d, new Object[] { smsg });
    } catch (IllegalAccessException e) {
    and I have define d1 as;
    private static Object d1 = new Object();
    Any ideas why I am getting the exception.
    Thanks,
    MS

Maybe you are looking for