Results 1 to 3 of 3

Thread: Classpath issues

  1. #1
    Join Date
    Aug 2004
    Posts
    29

    Default Classpath issues

    Hi I am having some problems getting spring to work inside an eclipse plugin. I am sure I am doing something wrong, but I can't figure out what.

    I have a plugin which loads a spring beans xml file in it's start method, using FileSystemXmlApplicationContext

    I have also placed all the third party jars (including the various spring related jars) I use in my plugin's <runtime> section.

    When I launch a runtime workbench I can see that spring loads my beans definition file
    but I get a class not found exception (the class that was not found is one of my beans
    which has also been included in the plugin in the same way as spring (lets call it MyBean).

    I was wondering if eclipse's classloading scheme was getting in the way, since I can even create an instance of MyBean 'prior' to using the FileSystemXmlApplicationContext and yet it will fail with a class not found exception.

  2. #2
    Join Date
    Aug 2004
    Posts
    29

    Default Re: Classpath issues

    Ok, I have found out how to get it to work. Please let me know if what I am doing is incorrect.

    I had to change the classloader for my current thread to that of my plugin's class.

    ClassLoader orig = Thread.currentThread().getContextClassLoader();
    try {
    Thread.currentThread().setContextClassLoader(MyPlu gin.class.getClassLoader());
    appContext = new FileSystemXmlApplicationContext("springapp.xml");
    } catch (Exception e) {
    .....
    }
    finally {
    Thread.currentThread().setContextClassLoader(orig) ;
    }

    Now it all works like a charm!

  3. #3
    Join Date
    Jun 2009
    Location
    Pune
    Posts
    10

    Default

    Quote Originally Posted by haninaguib View Post
    Ok, I have found out how to get it to work. Please let me know if what I am doing is incorrect.

    I had to change the classloader for my current thread to that of my plugin's class.

    ClassLoader orig = Thread.currentThread().getContextClassLoader();
    try {
    Thread.currentThread().setContextClassLoader(MyPlu gin.class.getClassLoader());
    appContext = new FileSystemXmlApplicationContext("springapp.xml");
    } catch (Exception e) {
    .....
    }
    finally {
    Thread.currentThread().setContextClassLoader(orig) ;
    }

    Now it all works like a charm!
    I think the exact location of the configuration file on the filesystem should be specified for FileSystemXmlApplicationContext

Similar Threads

  1. Replies: 9
    Last Post: Feb 15th, 2012, 12:19 PM
  2. Issues with multithreading and controllers?
    By brianstclair in forum Web
    Replies: 16
    Last Post: Feb 19th, 2010, 10:57 AM
  3. Replies: 4
    Last Post: Oct 6th, 2009, 12:08 PM
  4. Accessing classpath resources from within a jar
    By general_pattonm in forum Container
    Replies: 9
    Last Post: May 15th, 2008, 05:14 PM
  5. Replies: 6
    Last Post: Dec 18th, 2007, 09:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •