Setting the Java build path

This section describes how to set the Java build path, i.e. the classpath used for building a Java project. A classpath is an array of classpath entries accounting for available types either in source or binary form, which are used in order to find available types. The ordering of these entries defines the precedence of the available types.

The Java build path also governs the structure of a Java project element, since all package fragment roots directly derived from the Java build path (each entry maps to one or more package fragment roots, see getPackageFragmentRoots).

This section does not cover the Java runtime path which can be defined separately, see the related section on how to run Java programs.

Changing the build path

You can programmatically change a project's build path using setRawClasspath on the corresponding project's Java element, for example:

	IProject project = ... // get some project resource
	IJavaProject javaProject = JavaCore.create(project);
	IClasspathEntry[] newClasspath = ...;
	javaProject.setRawClasspath(newClasspath, someProgressMonitor);
	
Note that there also exists a variant of setRawClasspath which lets the Java build path and the project output location to be defined at the same time.

The Java build path is persisted into a file named '.classpath' under the project location. The purpose of this file is to provide a way to share Java build path settings with others through some source code repository. In particular, this file should not be manually edited, since it may get corrupted.

Classpath entries

Classpath entries can be defined using factory methods defined on JavaCore, so as to reference any of the following:

Classpath resolution

Due to the presence of dynamically bound entries (classpath variables and containers), JDT Core distinguishes the notion of a raw versus a resolved classpath. The raw classpath is the one originally set on the Java project using setRawClasspath, and can be further queried by asking the project for getRawClasspath.

It is also possible to query for the resolved classpath of a project, using getResolvedClasspath. This operation triggers initialization of involved variable(s) and/or container(s) if necessary. Note that many Java Model operations implicitly cause the Java build path to be resolved, e.g. computing a project package fragment roots requires the build path to be resolved.

 Copyright IBM Corporation and others 2000, 2002. All Rights Reserved.