Place Line Numbers In Eclipse

To place line numbers to the left of Java source code in Eclipse, do the following.

Window → Preferences.... → General → Editors → Text Editors → Show line numbers → OK

  1. Left mouse click the Window drop down menu at the top of the "Java Perspective".

  2. Left mouse click the Preferences.... menu item at the bottom of "Window" menu.

  3. In the "Preferences" dialog box, double left mouse click the General item

  4. Under "General", double left mouse click the Editors item.

  5. Under "Editors", left mouse click the Text Editors item

  6. In the "Text Editors" frame to the right, place a check the check box beside Show line numbers.

  7. Click OK. Compare with the following dialog box.

Place Line Numbers In WORD

Note: Versions of Eclipse through 3.3 do not support the printing of line numbers to a printer or clip board. Copy and paste does not retain the line numbers.

One work around is to convert the Java source code to an html or rtf (rich text file) format with a program that both generates syntax highlighting and numbers the lines of the source code. One such program that does this is Java2Html.

I have found that rtf files retain indentation whereas html files sometimes lose the appropriate indentation. I also observed that Java2Html formated html files get inserted as tables when read into WORD and WordPerfect, but not so for rtf files. I recommend convertions to the rtf format.

Using Java2Html, copy the rtf code into a text editor such as TextPad. Remember to tick the check box for generating "Line Numbers" and to choose "RTF" in the "Target" drop down menu before clicking the "Convert" button. Save the resulting text file with the appropriate "rtf" extension.

The resulting rtf file retains syntax highlighting, indentation and line numbering when inserted into a current version of WORD or WordPerfect after Insert --> File....

Caveat: Lines are not automatically renumbered if deleted or inserted in code after it has been converted. Code must be again converted by running Java2Html if lines are deleted or inserted or modified such to trigger either situation, as could happen if code were modified in the wordprocessor.

URL:    Last Revised:  November 13, 2007