PDA

View Full Version : Classpath issues



haninaguib
Aug 12th, 2004, 10:54 AM
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.

haninaguib
Aug 12th, 2004, 01:38 PM
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! :)

satish_psr
Jun 21st, 2009, 07:30 AM
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