Build Paths and Timing with Eclipse

  1. Adding .class files to the Build Path

  2. Timing with Eclipse


Adding .class files to the Build Path

Suppose you don't have the source .java file for some class that your program is using, but you do have the compiled .class file. How do you build your program in Eclipse?

For example, suppose you have these source files:

and this compiled file:

The first source file MysteryTimerApp uses Mystery. So it can't be compiled unless the compiler, javac, can find the Mystery.class file.

Eclipse only looks for source files (.java files) in the src directory.

The bin directory is the "output" directory - where it puts the files it compiles.

So Mystery.class doesn't belong in either of these directories.

Step by step directions in Eclipse

  1. Create a Java Project

    I will use the name 'mysterious' in these directions. If you use a different name, replace mysterious with your project name.

  2. Under the file menu, choose New and create a new folder.

    I'll use the name 'lib' for the folder.

    This folder will be used to hold .class files (e.g. Mystery.class) needed to compile the .java source files of the project (MysteryTimerApp.java and timer.java).

  3. Change the project settings to let Eclipse know that the lib folder should be searched for input class files when compiling.

    Under the Project menu select properties to get this dialog:

    Project Settings

  4. Click the Add Class Folder button to get the following dialog and check the box for the lib folder.

    select the folder you created for
	input class files

  5. Copy MysteryTimer.java and timer.app into the project src folder.

  6. Copy Mystery.class into the project lib folder.

Following these steps should remove any compile errors resulting from references to Mystery since the compiler will now know to look in the lib folder during compilation for the Mystery.class file.

Timing with Eclipse [top]

Eclipse is interfering with timing. The problem is that Eclipse is using "just in time compiling" optimization during execution. Certain chunks of code will be "interpreted" one or more times, but then the jit compiler replaces the java byte code with native machine code. This means this chunk of code will run much faster if it is executed again during this run of the program. This obviously throws off any attempts to time execution.

To do timing in Eclipse, the jit compilation option needs to be turned off. The way to do this requires a few steps.

  1. Under the Run menu select Run Configurations... to get the following dialog. Click on Java Application and then click the icon in the upper left corner to get to the configuration dialog

    run configuration dialog

  2. In the configuration dialog that is now displayed, click the Arguments tab.

    In the VM arguments text box, type -Djava.compiler=none and click the Apply button.

    VM configuration to disable run
	time compile options

This disables the run time optimizations that are interfering with timing and you should now be able to get timings that are consistent and allow you to determine the likely complexity of each of the 7 functions.