开发者

How can I include line numbers in Java source code?

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?


You can use cat to do this

cat -n input.java > output.java


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)..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜