Add the JUnit container to classpath [message #250707] |
Thu, 17 January 2008 11:37 |
Eclipse User |
|
|
|
Hi all,
I am trying to create a Java project programmatically (i.e.
without using the wizard). What I want is to add JUnit as
a library in the project's classpath. Here's what I did to
do the same task for the JRE:
classpath.add( JavaRuntime.getDefaultJREContainerEntry() );
My question is: is there a similar way to do this for the JUnit
container?
My current approach is :
Path junit_path = JavaCore.getResolvedVariablePath("JUNIT_HOME")
.append("junit.jar");
classpath.add( JavaCore.newLibraryEntry(junit_path, null, null));
This successfully adds junit.jar in the project's classpath, in the
sense that I don't get any compilation errors. However, it doesn't
add the JUnit container in the classpath; just the jar file, so,
when I try to run the project's main method Eclipse complains about
being 'unable to read .classpath file for project ...'.
When I add the JUnit library by using menus and wizards
(Build Path > Add Libraries > JUnit) the above error does
not appear and the .classpath file is read normally.
I suspect that by adding JUnit in the classpath programmatically
I somehow corrupted the .classpath file, and hence the above error.
Does anyone know what is the correct way of adding JUnit
in the project's classpath programmatically?
Thanks in advance,
Florian
|
|
|
Powered by
FUDForum. Page generated in 0.02563 seconds