|
Re: Cannot load classes when running a plug-in [message #258107 is a reply to message #258081] |
Thu, 15 January 2009 00:40 |
Walter Harley Messages: 847 Registered: July 2009 |
Senior Member |
|
|
hadas wrote:
> Hello, everybody.
> I'm a student and new in eclipse and I have a problem that I'm dealing with
> for more then a week but haven't resolved yet:
> I'm developing a plugin(in java) - an expension to the eclipse IDE - that
> one of its features is running a unit test and generate a report of its
> results.
The quick, but flawed, answer is that you need to define your own
classloader, based on URLClassLoader.
The longer and better answer is that you need to think carefully about
exactly what classes you're trying to load in what processes, and what
the various classpaths you're dealing with are, and I think you'll
discover you're taking a bad approach right now.
The issue is that once you load a class, two things happen. First,
particularly on Windows, it is hard to unload it until you exit the
process. That means that if you're loading it in order to test it,
you're going to have to exit and restart the process in order to change
it and test it again. You probably don't want that.
Second, you are letting that class have access to everything in your
process space. For example, if it calls System.exit(), your process
will abruptly exit. If it throws an exception that you don't catch, the
thread will exit. And so forth. So loading an arbitrary user class
into your own VM is usually a no-no - ESPECIALLY if it's a class that
you're testing, that is, a class that is not already known to be safe
and correct.
So for those reasons, test cases are usually run in a separate process.
That's why you have "Run As... JUnit Test" in Eclipse: it launches a
separate process to execute JUnit in. That's also how I would recommend
you implement your feature: start a separate process and invoke JUnit
within it. An additional benefit of launching a separate process is
that you get to specify whatever classpath you want for that process.
So you can put the correct folder on that classpath and you don't need
to use a custom classloader.
As you've noticed already, the classpath that a plug-in's classes run in
includes just those plug-in classes, plus any classes in plug-ins that
it depends on. Nothing else. That's an intentional feature of OSGi,
the classloading platform that Eclipse is based on.
|
|
|
Powered by
FUDForum. Page generated in 0.03012 seconds