1

I'm reaching the climax of my final year programming project, which is written in Java (using the Wicket web framework). I have to provide the examiners with the source code (on CD) with each line clearly numbered. I know that in Eclipse you can number the lines of code, but obviously this will only work if the person viewing the code uses Eclipse. Is there any way to include line numbers in the source code itself? If so, how?

1
  • 1
    Most IDEs have options to turn on line numbers. Unless the examiner is going to be using notepad/wordpad, you should be fine.Out of curiosity, why are line numbers so important ? Commented Mar 27, 2011 at 19:46

5 Answers 5

3

You can use cat to do this

cat -n input.java > output.java
Sign up to request clarification or add additional context in comments.

1 Comment

Nice; I didn't know that cat could do that. However, nl has more options to let you control the formatting.
1

Write a litte java program to read your .java files and ouput them in new files with line numbers?

Comments

1

That sounds like a strange requirement to me, because if you insert a line number at the beginning of each line in the file itself, it won't compile. Are you sure they're not actually asking for some kind of report that includes the source code (line numbers in the code itself only makes sense if the code is to be printed). Any decent text editor is able to both display line numbers and print them, without the numbers being a part of the file, so if I were an examiner, that's what I would use. But if this is indeed what the examiners want, you could use the unix command nl, or write your own program that does it.

1 Comment

+1 for nl, and for pointing out that this seems like an odd requirement.
1

You could for example supply (probably in addition to the raw-text-sourcecode) an html version of your code (with or without syntax highlighting) which includes linenumbers. There are several tools I found by googling which do that, for example http://www.java2html.de/ . I think the JDK actually ships with such an application.

However, if it's just plain text you want, you could of course simply write a little routine to add linenumbers for you. Just read the lines of your code one by one, increment a counter and prepend the line with the current counter.

Comments

1

Use the JavaDoc tool with the -linksource option.

Creates an HTML version of each source file (with line numbers)..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.