Question

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?

Was it helpful?

Solution

You can use cat to do this

cat -n input.java > output.java

OTHER TIPS

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

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.

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.

Use the JavaDoc tool with the -linksource option.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top