Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Add the JUnit container to classpath
Add the JUnit container to classpath [message #250707] Thu, 17 January 2008 11:37
Eclipse UserFriend
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
Previous Topic:Running a single test in /org.eclipse.jdt.core.tests.compiler/ with a 1.5 jre ?
Next Topic:eclipse does not start
Goto Forum:
  


Current Time: Tue May 06 13:32:59 EDT 2025

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

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

Back to the top