Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » PDE JUnit and NoClassDefFoundException
PDE JUnit and NoClassDefFoundException [message #151123] Sat, 27 March 2004 10:15 Go to next message
Eclipse UserFriend
Hi,

I' like to test my Plugin with PDE JUnit.
This is my configuration:
Eclipse 2.1.3
JDK 1.3
PDE JUnit 2.1.5
JUnit 3.8.1

I've created a separate "Test Plugin" which tries to create an instance of
class MyPluginClass within my "Productive Plugin":

public class ExampleTest extends TestCase {
public void simpleTest() {
MyPluginClass m = new MyPluginClass();
}
}

When I invoke the testcase with "Run As > JUnit Plug-In Test" the
PluginClassLoader throws a NoClassDefFoundException.

I found a thread in the newsgroups which was discussing about setting the
ContextClassLoader manually for the current thread. Thus I've tried this:

public class ExampleTest extends TestCase {
public void simpleTest() {
Thread thread= Thread.currentThread();
ClassLoader oldClassLoader= thread.getContextClassLoader();
ClassLoader pluginClassLoader= MyPlugin.class.getClassLoader();
try {
thread.setContextClassLoader(pluginClassLoader);
// do call
MyPluginClass m = new MyPluginClass();
} finally {
thread.setContextClassLoader(oldClassLoader);
}
}
}

But PluginClassLoader throws a NoClassDefFoundException at
'MyPlugin.class.getClassLoader();'.

BTW: MyPluginClass is found when I invoke the testcase with "JUnit Test"
(but the plugin context is missing then).

Any ideas? Do I have to define any extensions points in my "Productive
Plugin"?

Many thanks!

Regards,
Jan.
Re: PDE JUnit and NoClassDefFoundException [message #151256 is a reply to message #151123] Sun, 28 March 2004 14:03 Go to previous messageGo to next message
Eclipse UserFriend
Well... I found that "solution":

copy myplugin.jar to the lib/ directory of my test plugin project.

extend plugin.xml:
<runtime>
<library name="lib/myplugin.jar">
<export name="*"/>
</library>
...
</runtime>

Every time I changed my Plugin and want to test it, I do a "deploy test" ant
task which copies my plugin to the test plugin project.

I don't like the approach but the PDE JUnit Plugin is working at least. If
anybody has has a better solution, please mail me.

Regards,
Jan.

"Jan-Friedrich Mutter" <krabatz@gmx.net> schrieb im Newsbeitrag
news:c445i1$i0e$1@eclipse.org...
> Hi,
>
> I' like to test my Plugin with PDE JUnit.
> This is my configuration:
> Eclipse 2.1.3
> JDK 1.3
> PDE JUnit 2.1.5
> JUnit 3.8.1
>
> I've created a separate "Test Plugin" which tries to create an instance of
> class MyPluginClass within my "Productive Plugin":
>
> public class ExampleTest extends TestCase {
> public void simpleTest() {
> MyPluginClass m = new MyPluginClass();
> }
> }
>
> When I invoke the testcase with "Run As > JUnit Plug-In Test" the
> PluginClassLoader throws a NoClassDefFoundException.
>
> I found a thread in the newsgroups which was discussing about setting the
> ContextClassLoader manually for the current thread. Thus I've tried this:
>
> public class ExampleTest extends TestCase {
> public void simpleTest() {
> Thread thread= Thread.currentThread();
> ClassLoader oldClassLoader= thread.getContextClassLoader();
> ClassLoader pluginClassLoader= MyPlugin.class.getClassLoader();
> try {
> thread.setContextClassLoader(pluginClassLoader);
> // do call
> MyPluginClass m = new MyPluginClass();
> } finally {
> thread.setContextClassLoader(oldClassLoader);
> }
> }
> }
>
> But PluginClassLoader throws a NoClassDefFoundException at
> 'MyPlugin.class.getClassLoader();'.
>
> BTW: MyPluginClass is found when I invoke the testcase with "JUnit Test"
> (but the plugin context is missing then).
>
> Any ideas? Do I have to define any extensions points in my "Productive
> Plugin"?
>
> Many thanks!
>
> Regards,
> Jan.
>
>
Re: PDE JUnit and NoClassDefFoundException [message #151287 is a reply to message #151256] Mon, 29 March 2004 05:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: thomas_maeder.ch.ibm.com

Have you tried requiring the productive plugin in your test plugin?

Jan-Friedrich Mutter wrote:

> Well... I found that "solution":
>
> copy myplugin.jar to the lib/ directory of my test plugin project.
>
> extend plugin.xml:
> <runtime>
> <library name="lib/myplugin.jar">
> <export name="*"/>
> </library>
> ...
> </runtime>
>
> Every time I changed my Plugin and want to test it, I do a "deploy test" ant
> task which copies my plugin to the test plugin project.
>
> I don't like the approach but the PDE JUnit Plugin is working at least. If
> anybody has has a better solution, please mail me.
>
> Regards,
> Jan.
>
> "Jan-Friedrich Mutter" <krabatz@gmx.net> schrieb im Newsbeitrag
> news:c445i1$i0e$1@eclipse.org...
>
>>Hi,
>>
>>I' like to test my Plugin with PDE JUnit.
>>This is my configuration:
>>Eclipse 2.1.3
>>JDK 1.3
>>PDE JUnit 2.1.5
>>JUnit 3.8.1
>>
>>I've created a separate "Test Plugin" which tries to create an instance of
>>class MyPluginClass within my "Productive Plugin":
>>
>>public class ExampleTest extends TestCase {
>> public void simpleTest() {
>> MyPluginClass m = new MyPluginClass();
>> }
>>}
>>
>>When I invoke the testcase with "Run As > JUnit Plug-In Test" the
>>PluginClassLoader throws a NoClassDefFoundException.
>>
>>I found a thread in the newsgroups which was discussing about setting the
>>ContextClassLoader manually for the current thread. Thus I've tried this:
>>
>>public class ExampleTest extends TestCase {
>> public void simpleTest() {
>> Thread thread= Thread.currentThread();
>> ClassLoader oldClassLoader= thread.getContextClassLoader();
>> ClassLoader pluginClassLoader= MyPlugin.class.getClassLoader();
>> try {
>> thread.setContextClassLoader(pluginClassLoader);
>> // do call
>> MyPluginClass m = new MyPluginClass();
>> } finally {
>> thread.setContextClassLoader(oldClassLoader);
>> }
>> }
>>}
>>
>>But PluginClassLoader throws a NoClassDefFoundException at
>>'MyPlugin.class.getClassLoader();'.
>>
>>BTW: MyPluginClass is found when I invoke the testcase with "JUnit Test"
>>(but the plugin context is missing then).
>>
>>Any ideas? Do I have to define any extensions points in my "Productive
>>Plugin"?
>>
>>Many thanks!
>>
>>Regards,
>>Jan.
>>
>>
>
>
>
Re: PDE JUnit and NoClassDefFoundException [message #151454 is a reply to message #151287] Mon, 29 March 2004 16:37 Go to previous message
Eclipse UserFriend
Yes, I did (and do).

Funny that the Plugin Classloader (which is different from the "normal"
classloader) doesn't find my productive plugin but all other plugins like
e.g. org.apache.xerces (which is only imported in my workspace as an
external plugin and added to the classpath as an external project).

According to the thread of
http://dev.eclipse.org/newslists/news.eclipse.tools/msg48636 .html
there's a required plugin which does not specify my plugin as one of the
plugins it requires, therefore it cannot see my class.

Thanks for reply.

Regards,
Jan.

"Thomas M
Previous Topic:New project files
Next Topic:Threads and Monitors Panel on Mac OS X
Goto Forum:
  


Current Time: Thu Sep 18 10:14:12 EDT 2025

Powered by FUDForum. Page generated in 0.03941 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top