Set Classpath in Eclipse and NetBeans: a Short Comparison

How to set project classpath in Eclipse and NetBeans are similar: just right-click the project name, choose Properties to bring up the Properties Window. But there are some small variations between the two, mostly of the nature of ease-of-use, or style.

How to set classpath in NetBeans:

In NetBeans Project Properties Window, you click Libraries in the left panel, and in the right panel are 4 categories of classpath you can configure:
  • Compile: Empty by default. Compile-time libraries are automatically propagated to other categories of classpath, so you don't need to repeat the same set of jar files in all 4 categories.

  • Run: By default includes everything in compile-time classpath, and compiled classes (e.g., build/classes).

  • Compile Tests: By default includes everything in compile-time classpath, compiled classes (e.g., build/classes), and JUnit.

  • Run Tests: By default includes classpath for compiling tests, and compiled tests.
The separation of the 4 categories of classpath offers a great deal of flexibility, and in most cases, common-sense default values are used to save configuration efforts. Depending on project types, you may see fewer categories of classpath in NetBeans. For instance, there is no Run classpath for web application project, since we don't directly run a war file.

How to set classpath in Eclipse:

Eclipse manages run classpath and build/compile classpath in different places. To configure run classpath, go to menu Run | Run ... to open up the Run Dialog Window. Your current project should already be selected, otherwise, expand the Java Application node in the left panel and select it. Click Classpath tab in the right panel. The default classpath for the current project is the output folder where all compiled classes reside. You can then click any of these buttons to modify run classpath: Add Projects, Add JARS, Add External JARS, Advanced, etc.

To configure build classpath, in Eclipse Project Properties Window, click Java Build Path in the left panel, and in the right panel choose Libraries tab. There are more classpath-related elements in Eclipse: JARs, External JARS, Variables, Libraries, Class Folders, and other Projects. Click Add External JARs (not Add JARS) if you want to add a jar file to classpath, and click Add Class Folders if you want to add a directory or folder to classpath.

It seems to me Add Variables, Add Libraries, and Add JARS all add collections of classpath elements that are defined inside Eclipse, but I don't know their differences. When I specify classpath in any IDE, I like to explicitly spell out Jar files and directories, without using any IDE-specific artifacts. I suppose the whole purpose of having them is to reuse them in other projects, but I find it's pretty unrealistic due to various jar version differences.

I don't care about the difference between a jar file and a directory, both of them are just an element in the classpath. I like the fact that NetBeans combine them into one single Add JAR/Folder button.

When I create a project in Eclipse 3.2, the default output folder is set to the same folder as source folder, which is not a good idea. At least for me, I don't like mixing class files along with java source files. Wouldn't that also slow down classloading when JVM searches classes, since there are twice as many files to scan. You can change the output folder in project property window | Java Build Path.

Followers

Pageviews Last 7 Days