Announcement Announcement Module
Collapse
No announcement yet.
Classpath issues Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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!

    Comment


    • #3
      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

      Comment

      Working...
      X