Skip to Content

JDT Projects

If you're working in Eclipse with Java projects, you work with JDT (Java Development Tools) projects. A project that is a JDT project has the org.eclipse.jdt.core.javanature nature and contains usualy at least a org.eclipse.jdt.core.javabuilder builder, that is responsible for (incrementally) building the project. Ant4Eclipse JDT-related tasks gives you access to all those JDT-specific settings.

JDT classpathes

Each JDT project declares a single classpath, that both works as a classpath when compiling your project ("compile-time classpath") and when you run it ("runtime classpath"). Both, compile and runtime classpath, are resolved from the same classpath definition that is stored in your projects .classpath file. A JDT classpath definition contains a set of classpath entries. There are several kinds of entries that all can be used in a single classpath:

  • Directories and JAR files: You can add Jar-files and directories to your project classpath. Those elements can be part of your project or reside outside of your project. This kind of classpath entry is very similar to a classpath entry that you can specify when using the -classpath argument with java or javac.
  • Project references:When specifying a reference to another Eclipse project (that must reside in your workspace) you add this project's classpath to your own classpath. This works recursive for all entries of the referenced project, as long as a runtime classpath should be resolved. If the classpath is resolved for compiling only those entries from a referenced project are added to your classpath, that are explizitly "exported" (Project properties -> Java Build Path -> Order and Export)
  • Classpath Variables: Classpath Variables are placeholders that point to a single path (directory or file). Variables can be contributed by Plug-ins (for example ECLIPSE_HOME). It's also possible to specify own variables (Preferences -> Java -> Build path -> Classpath Variable).
  • Libraries: Libraries can be used to add a set of additional entries to your classpath. Libraries can be contributed by Plug-ins (for example the "JRE System library" or the "Plug-in dependencies" library contributed by the PDE), but you can define your own libraries as well ("User libraries" defined via Preferences -> Java -> Build path -> User libraries). In opposite to Classpath Variables Libraries can be either static (as Classpath Variables) or dynamic. In case they are dynamic the actual entries they contribute are determined each time Eclipse (resp. ant4eclipse) needs to resolve the classpath. Imagine the "Plug-in dependencies" library as an example. You can add this library to all of your projects. But the entries the library adds to your project differ (not only from project to project, but even in the lifetime of a single project: each time you add a dependencie to your plug-in the added entries change)

Resolving a classpath

An important ant4eclipse feature is to correctly resolve a classpath that has been defined in Eclipse. This way ant4eclipse is able to calculate the correct build order of a set of projects according to their dependencies.
When ant4eclipse resolves a classpath for you, it takes all configurations that are stored directly in your projects into account. But there are some configurations that are not part of your project. JRE definitions for example are stored in the .metadata folder of your workspace, thus they are not available (for ant4eclipse) when you check your projects from your source code repository to a "clean" place where you want to start your build. The workspace settings have to be redefined in your build scripts. In the following sections we’ll show you how to do that. You will see that it’s quite easy.