Frequently Asked Questions on JDT

Can I use a Java compiler other than the built-in one (javac for example) with the workbench?

No. The JDT provides a number of sophisticated features including fully automatic incremental compilation, code snippet evaluation, code assist, type hierarchies, and hot code replace. These features require special support found in the workbench Java compiler (an integral part of the JDT's incremental project builder), but not available in standard Java compilers.

Where do Java packages come from?

A project contains only files and folders. The notion of a Java package is introduced by a Java project's class path (at the UI, the Package Explorer presents the packages as defined by the classpath). Tip: If the package structure is not what you expect, check out your class path. The Java search infrastructure only finds declarations for and references from Java elements on the class path.

When do I use an internal versus an external JAR library file?

An internal resource resides in some project in the workbench and is therefore managed by the workbench; like other resources, these resources can be version managed by the workbench. An external resource is not part of the workbench and can be used only by reference. For example, a JRE is often external and very large, and there is no need to associate it with a VCM system.

When should I use source folders within a Java project?

Each Java project locates its Java source files via one or more source type entries on the project's class path. Use source folders to organize the packages of a large project into useful grouping, or to keep source code separate from other files in the same project. Also, use source folders if you have files (documentation for example) which need not be on the build path.

What are source attachments, How do I define one?

Libraries are stored as JAR files containing binary class files (and perhaps other resources). These binary class files provide signature information for packages, classes, methods, and fields. This information is sufficient to compile or run against, but contains far less information that the original source code. In order to make it easier to browse and debug binary libraries, there is a mechanism for associating a corresponding source JAR (or ZIP) file with a binary JAR file.

Why are all my resources duplicated in the output folder (bin, for example)?

If your Java project is using source folders, then in the course of compiling the source files in the project, the Java compiler copies non-Java resources to the output folder as well so that they will be available on the class path of the running program. To avoid certain resources to be copied to the output location you can set a resource filter in the Java compiler preferences: Window > Preferences > Java > Compiler > Building

How do I prevent having my documentation files from being copied to the project's output folder?

Use source folders and put any resources that you do not want to be copied to the output folder into a separate folder that is not included on the class path. You can also set a resource filter in the Java compiler preferences: Window > Preferences > Java > Compiler > Building to for example *.doc.

How do I create a default package?

You don't have to. Files in the root folder of a source folder or project are considered to be in the default package. In effect, every source folder has the capability of having a fragment of the default package.

What is refactoring?

Refactoring means behavior-preserving program transformations. The JDT supports a number of transformations described in Martin Fowler's book Refactoring: Improving the Design of Existing Code, Addison-Wisely 1999.

When do I use Open Declaration (F3)?

To find out the Java element that corresponds to the selected source range with the help of the compiler.

Is the Java program information (type hierarchy, declarations, references, for example) produced by the Java builder? Is it still updated when auto-build is off?

The Java program information is independent from the Java builder. It is automatically updated when performing resource changes or Java operations. In particular, all the functionality offered by the Java tooling (for example, type hierarchies, code assisting, search) will continue to perform accurately when auto-build is off; for example, when doing heavy refactoring which require to turn off the builders, you can still use code assist, which will reflect the latest changes (not yet build). Other than the launching (that is, running and debugging) of programs, the only functionality which requires the Java builder is the evaluation of code snippets.

After reopening a workbench, the first build that happens after editing a Java source file seems to take a long time. Why is that?

The Java incremental project builder saves its internal state to a file when the workbench is closed. On the first build after the project is reopened, the Java incremental project builder will restore its internal state. When this file is large, the user experiences an unusually long build delay.

I can't see a type hierarchy for my class. What can I do?

Check that you have your build class path set up properly. Setting up the proper build class path is an important task when doing Java development. Without the correct build path, you will not be able to compile your code. In addition, you will not be able to search or look at the type hierarchies for Java elements.

How do I turn off "auto compile" and do it manually when I want?

Clear the Build automatically checkbox on the Opens the Workspace preference page General > Workspace preference page. When you want to build, press Ctrl+B, or select Project > Build All from the menu bar.

Hint: when you turn "auto compile" off and build manually, you may also want to select the Save automatically before build checkbox on the Opens the Workspace preference page General > Workspace preference page.

When I select a method or a field in the Outline view, only the source for that element is shown in the editor. What do I do to see the source of the whole file?

There is a toolbar button Show Source of Selected Element Only - all you have to do is un-press it.

Can I nest source folders?

Yes, you can use exclusion filters to create nested source folders.

Can I have separate output folders for each source folder?

Yes, select the Allow output folders for source folders checkbox in the Java Build Path > Source property page of your Java project.

Can I have an output or source folder that is located outside of the workspace?

Yes, you can create a linked folder that points to the desired location and use that folder as the source or output folder in your Java project.

Related concepts

Java development tools (JDT)

Related reference

Java build path page
JDT glossary