Introduction
Setting Java project build path involves setting classpaths of the project which are different from the Java runtime classpath. In JDT classpaths are represented with classpath entries which roughly fall into five kinds: source folder entries, binary library entries, prerequisite project entries, classpath variables, and classpath containers.
Start you eclipse JDT, open a Java project and launch the build path configuration window, and you’ll find all the options enabling you to add/remove all kinds of classpath entries. The frequently used JAVA_HOME system variable (under Windows) can be considered as a classpath variable here. And for a classpath container, hereafter comes more.
Classpath Container
Conceptually it is a data structure which represents a set of tupes with each in the form of
IClasspathEntry(kind: container)-aContainerPath –>
Ways of Creating Classpath Container Entries
The implementation details are more complicated. Class or interfaces involved in include JavaModelManager, JavaCore, IClasspathEntry, ClassContainer, IClassContainerInitializer, and other Java Model classes. The set of tupes of the form of
Generally, there’re two ways of creating a classpath container entry. The 1st way is to hard code creating instances of ClasspathContainer, and the 2nd way is to create instances of ClasspathContainer via the lazily invoked classpath container initializer which you may define onto the extension point org.eclipse.jdt.core.classpathContainerInitializer.
The hard code way:
// create an instance of IClasspathEntry of kind CPE_CONTAINER
// but ClasspathContainer associated to this entry are not yet defined.
JavaCore.newContainerEntry(..);
…
// Create and set the classpath container
JavaCore.setClasspathContainer(..);
…
// Put container path, containers and projects into hashmaps.
// Invoked in JavaCore.setClasspathContainer(..).
JavaModelManager.containerPut(..)
The initializer way:
// Contribute an extension to the initializer extension point.
When classpath entries contained in containers get resolved, the execution process is:
// Methods resolving classpath entries will get method getClasspathContainer(..) invoked.
JavaCore.getClasspathContainer(..);
…
JavaModelManager.getClasspathContainer(..);
…
// Both ways would get this method invoked.
JavaModelManager.containerGet(..);
…
// The initializer way would get this method invoked,
// within which initializer extension(s) will be lazily invoked.
JavaModelManager.initializeAllContainers(..);
or JavaModelManager.initializeContainer(..);
Resources
- Setting the Java build path
- JDT 3.2 Source Codes.

No comments:
Post a Comment