Eclipse FAQ
Spring 2006, David Matuszek

This FAQ should be correct for Eclipse 3.1.1; however, in some cases the answers may be based on an older version of Eclipse.

  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?

    Go to Window -> Preferences -> Java -> Compiler -> Compliance and Classfiles and set Compiler Compliance Level to 5.0. Also check Use Default compliance settings. This tells the compiler to recognize and allow assert statements, but does not enable them.
    If you must use Java 1.4, there's a lot more you need to do:
    Compiler Compliance Level: to 1.4
    Use default compliance settings to unchecked
    Generated .class files compatibility: to 1.4
    Source compatibility: to 1.4
    Disallow identifiers called 'assert': to Error
    Compiler Compliance Level to 1.4
    The above will make assert statements legal to have in your code, but they will be disabled (they won't actually do anything). To enable assert statements, you must set a flag to the compiler. Go to Run -> Run... -> 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 Window -> Preferences -> Editor -> Appearance and check Show line numbers

  3. How do I get soft tabs?

    This should be the default. If not...

    To get soft tabs (tabs replaced by spaces) as you type, and when you reformat code, go to Window -> Preferences -> Java -> Code Style -> Formatter and choose Java Conventions [built-in] from the Select a profile: drop-down list. (Or create your own set of formatting conventions.)

    You can create your own profile by clicking Show...; for soft tabs, go to Indentation and uncheck Use tab characters. After making your changes, you will be prompted for a name for your new profile.

  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..., or choose File -> Export... -> Javadoc -> Next>
      • 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:
        • Windows: C:\Program Files\Java\j2sdk1.5.0\bin\javadoc.exe, (or something similar)
        • Macintosh: System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Commands/javadoc
    3. Select the project from the list of currently open projects, and select the destination for the javadoc files.
    4. Select the level of documentation (public through private). Other people should usually just see documentation for your public fields and methods, but you may want more extensive documentation for your own use.
    5. If you have no assert statements, you can click Finish at this point.
    6. Click Next >
    7. Click Next >
    8. Set JRE source compatibility: to either 1.4 or 1.5 (otherwise your assert statements will be treated as errors). [See also How do I get the assert statement to work?]
    9. 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/j2se/1.5.0/download.jsp and choose to download the JDK 5.0 Source Code (SCSL and JRL are just licenses; probably SCSL is best).
    2. For JDK 5.0, select Download(SCSL source) .
    3. Register. This is relatively painless, especially if you either ignore or enjoy reading license agreements.
    4. Download JDK (SCSL) 5.0 (1.5.0). This will give you a file jdk-1_5_0-src.scsl.zip. Do not unzip this file; Eclipse likes it the way it is.
    5. In Eclipse, go to Projects -> Properties -> Java Build Path -> Libraries and expand JRE System Library [jre 1.5.0], then expand rt.jar. Select Source attachment and click Edit....
    6. Navigate to the above zip file and select it.
    7. Finish by exiting the dialog boxes.

  6. Why are my JUnit results not showing up?

    Maybe it's because all your tests succeeded. For more satisfying results, go to Window -> Preferences -> Java -> JUnit and uncheck Show the JUnit results view only when an error or failure occurs.

  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. If you later add test classes, you can manually add them to this test suite.

  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?

    Here are two ways that work. First,
    1. In your workspace folder, create a new folder, and put your files into that folder.
    2. Ask Eclipse to create a new project (File -> New -> Project...) and, for the name of the project, type in the exact name of your new folder.
    3. Click Finish.
    The second way is very similar:
    1. Ask Eclipse to create a new project (File -> New -> Project...) with any suitable name.
    2. Copy your files into the new folder.
    3. In Eclipse's Package Explorer pane, right-click on the new project and choose Refresh from the pull-down menu.