Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 322557 - java.lang.NoClassDefFoundError: JUnit when running JUnit test from Run Configurations
Summary: java.lang.NoClassDefFoundError: JUnit when running JUnit test from Run Config...
Status: RESOLVED WONTFIX
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-12 12:07 EDT by Aaron CLA
Modified: 2010-08-30 09:56 EDT (History)
2 users (show)

See Also:


Attachments
screen shot of error msg when focus is in console window (15.03 KB, image/pjpeg)
2010-08-12 14:05 EDT, Aaron CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron CLA 2010-08-12 12:07:37 EDT
Build Identifier: 20100218-1602

When I run a JUnit test from Run>Run Configuration with the VM argument 
-Dprojloc=${project_name}, I get a java.lang.NoClassDefFoundError: JUnit exception. 

My workaround is to rename the project to remove all spaces in the project name using Project + Right Click>Refactor>Rename.

Reproducible: Always

Steps to Reproduce:
1.Create a JUnit project with spaces in project name
2.Create Run Configuration to run the JUnit test (JUnit 4)
3.Use the following VM argument -Dprojloc=${project_name} in the Run Configuration.
4.Run the test using the Run Configuration
Comment 1 Aaron CLA 2010-08-12 13:41:30 EDT
Can run JUnit tests without throwing an exception by Project + Right Click>Run As>3 JUnit Test. However you can't use a Run Configuration to do this and hence cannot use VM arguments to pass in Eclipse variables through the system properties mechanism.
Comment 2 Aaron CLA 2010-08-12 13:46:05 EDT
java.lang.NoClassDefFoundError: JUnit
Caused by: java.lang.ClassNotFoundException: JUnit
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Exception in thread "main"
Comment 3 Aaron CLA 2010-08-12 13:49:42 EDT
If I click inside the console window and re-rerun the JUnit test with the Run Configuration, I get this error message popup.

Variable references empty selection: ${project_name}
Comment 4 Aaron CLA 2010-08-12 14:01:22 EDT
(In reply to comment #3)
> If I click inside the console window and re-rerun the JUnit test with the Run
> Configuration, I get this error message popup.
> Variable references empty selection: ${project_name}

Note that to get this error, the focus remains in the Console output window and I run the JUnit test by going to the menu and doing Run>Run Configurations and picking the configuration for my test.
Comment 5 Aaron CLA 2010-08-12 14:05:27 EDT
Created attachment 176488 [details]
screen shot of error msg when focus is in console window
Comment 6 Aaron CLA 2010-08-12 14:23:26 EDT
The "Variable references empty selection" part of this bug report is related to this bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=292732

The original part of this bug report (the NoClassDefFoundError part) is still valid.
Comment 7 Kathy Chan CLA 2010-08-17 18:55:14 EDT
Jerome,

Please target and handle.
Comment 8 Bozier jerome CLA 2010-08-18 10:12:40 EDT
trying to reproduce it to size the fixing
Comment 9 Bozier jerome CLA 2010-08-25 08:47:13 EDT
after some investigation (thanks Julian) :
. when you use right click => run as => test : it is a TPTP run
. when you use right click => run as => run configuration : it is a PDE / JDT run

so, bug is not on TPTP part

for information, a basic workaround is replacing -Dprojloc=${project_loc} by -Dprojloc="${project_loc}"
it seems to work on my side (the ClassNotFound exception is raised on the part of project name separated by space. using double quote fix it)

re-assigning problem to PDE team, hoping they can do something
Comment 10 Darin Wright CLA 2010-08-30 09:56:53 EDT
The correct approach is to use quotes, as you must always do when paths have spaces.