How do I count the number of lines of code in an Eclipse project?

Is there a way to count the number of lines of code in an eclipse project? I can see the total number of lines for each file, but I'd like to see how much is generated across the whole project.


Solution 1:

Check out the Eclipse Metrics plugin.

alt text

Note the 'Lines of code' statements.

Edit: Version 2 of Metrics, requiring Eclipse 3.5+, is available here http://metrics2.sourceforge.net/

Solution 2:

You need to use the JavaNCSS tool, see JavaNCSS - A Source Measurement Suite for Java

I can't find any working links to Eclipse plugins that incorporate this library, only stale broken links.

But you can run it:

  • as an Ant task
  • or as a Maven plugin: mvn javancss

Also see JCSC which includes NCSS.