Eclipse FAQ
Updated for Eclipse 3.5.1
Spring 2010 , David Matuszek

  1. How do I get the assert statement to work?
  2. How do I get line numbers?
  3. How do I get soft tabs ?
  4. How do I run Javadoc?
  5. How do I see the javadoc for Sun-supplied classes?
  6. Why are my JUnit results not showing up?
  7. How do I create a test suite?
  8. In JUnit, what's the difference between a "failure" and an "error"?
  9. Why does Source→Format really mess up my formatting?
  10. How do I import an existing program into Eclipse?

  1. How do I get the assert statement to work?

    In Eclipse 3.1, go to Eclipse → Preferences → Java → Compiler and set the Compiler Compliance Level to at least 1.4 (1.6 is recommended). Also check Use Default compliance settings. This tells the compiler to recognize and allow assert statements, but does not enable them.

    To enable (make active) assert statements, you must set a flag to the compiler. Go to Run → Run Configurations... → Arguments, and in the box labeled VM arguments:, enter either -enableassertions or just -ea. Accept the changes and close the dialog.

    To get Javadoc to recognize the assert statement, see How do I run Javadoc?

  2. How do I get line numbers?

    Go to Eclipse → Preferences... → General → Editors → Text Editors and check Show line numbers. (While you are here, you should also make sure Insert spaces for tabs is checked.)

  3. How do I get soft tabs (tabs replaced by spaces)?

    There are two changes you should make.
  4. How do I run Javadoc?

    1. In the Package Explorer window, choose the package or file for which you want to generate documentation.
    2. Choose Project → Generate Javadoc... → Next>
      1. If the dialog box displays the message The Javadoc command does not exist, then you need to click the Configure... button and locate javadoc.exe. You already have this file--it is in a directory with a name something like YourJavaDirectory/jdk1.6.0/bin/.
    3. Select the project, and the destination for the Javadoc files. Normally, you should only generate documentation for public fields and methods.
    4. If you have no assert statements, you can click Finish at this point.
    5. Click Next >.
    6. Click Next > again.
    7. Set JRE source compatibility to 1.4 or higher, otherwise your assert statements will be treated as errors). [See also How do I get the assert statement to work?]
    8. Click Finish.

  5. How do I see the javadoc for Sun-supplied classes?

    If you hover (don't click) your mouse over the name of a method, you should see a simplified Javadoc explanation. If this doesn't work for Sun-supplied methods, then you don't have the source code installed. Here's how to install the source code:
    1. Go to http://java.sun.com/javase/downloads/index.jsp and choose to download the Java SE 6 Source Code.
    2. Download the file named jdk-6u18-ea-src-b05-jrl-18_nov_2009.jar or similar (it is updated frequently).
    3. You may have to register. This is relatively painless, especially if you either ignore or enjoy reading license agreements.
    4. In Eclipse, go to Projects → Properties → Java Build Path → Libraries and expand JRE System Library [jvm 1.6], then rt.jar. Select Source attachment and click Edit....
    5. Select the above jar file.
    6. Finish by exiting the dialog boxes.
    Note: This has not been tested in its current form, and may need tweaking.

  6. Why are my JUnit results not showing up?

    Maybe it's because all your tests succeeded. For more satisfying results, go to the downward-pointing triangle at the right end of the JUnit pane, and make sure Show Failures Only is not checked.

  7. How do I create a test suite?

    Go to File → New → Other... → Java → JUnit → TestSuite, and click Next>. Select all the classes, and click Finish.

    You can run this test suite the same way you run other JUnit tests.

  8. In JUnit, what's the difference between a "failure" and an "error"?

    A failure is when one of your assertions fails--that is, your program does something wrong, and your JUnit test notices and reports the fact. An error is when some other Exception occurs--one you haven't tested for and didn't expect, such as a NullPointerException or an ArrayIndexOutOfBoundsException.

  9. Why does Source→Format really mess up my formatting?

    You have unmatched brackets, braces, or parentheses, and the code reformatter is doing the best it can. Find the syntax error (somewhere near the beginning of the messed up formatting), fix it, and reformat.

  10. How do I import an existing program into Eclipse?

    In the Package Explorer pane, right click in an open area and choose Import..., then Existing Projects into Workspace, then Next>. Browse to the project folder and select it. Make sure Copy projects into workspace is checked, and click Finish