I have a Java project in Eclipse with ~10 packages and ~10 class files per package. Is there a way to determine total lines of code for the whole project from within Eclipse? I am familiar with other tools (e.g., Code Analyzer, wc, etc.) but I want to know if there is a way to do this within Eclipse (or get confirmation that there is no way to do it).
9 Answers
Search
> File Search
Check the Regular expression
box.
Use this expression:
\n[\s]*
Select whatever file types (*.java
, *.xml
, etc..) and working sets are appropriate for you.

- 2,888
- 1
- 25
- 36

- 6,693
- 14
- 54
- 69
-
21... and by `check off` you mean, `make sure it is checked`. Note that this method does not count empty lines. – Peter Ajtai Nov 12 '11 at 00:07
-
You may or may not have got this from [here](http://www.binaryfrost.com/index.php?/archives/207-Easy-way-to-count-Lines-of-Code-in-Eclipse.html). – Cam Jackson Jan 16 '12 at 04:27
-
1This will use up a lot of memory on larger codebases, unfortunately. On my Indigo I hit 700k hits before eclipse died. Granted I only have -Xmx314M in my eclipse.ini – sandos Jan 19 '12 at 10:54
-
1This gives each file's LOC individually. not TOC – Abhishek Susarla Mar 30 '12 at 11:28
-
8As mentioned by @PeterAjtai, it does not count empty lines. However, this will: `\n[^\n]*` – MiniGod Jul 24 '12 at 17:10
-
@AbhishekSusarla You can run it on packages. – sdasdadas Jul 19 '13 at 17:18
-
@CamJackson you're link is dead; anyway i definitely got it from somewhere, just can't remember else i'd have just posted the link... – Brian Sweeney Jan 28 '14 at 18:54
-
8To return a count of non-blank, non-comment lines something like this could help. `\n[^!//][\s]*` – Sean F May 08 '14 at 06:03
-
1This search usually hangs Eclipse (4.2.1) on my moderate size project. – Skull Jul 06 '14 at 08:10
Here's a good metrics plugin that displays number of lines of code and much more:
http://metrics.sourceforge.net/
It says it requires Eclipse 3.1, although I imagine they mean 3.1+
Here's another metrics plugin that's been tested on Ganymede:

- 11,479
- 5
- 49
- 73
-
61Note that http://metrics2.sourceforge.net/ states that the first plugin above (http://metrics.sourceforge.net/) is discontinued and metric2 is intended to be a continuation. – Bert F Oct 20 '10 at 18:50
-
2An information that would saved me a ton of time: The plugin needs to be activated for each project in your workspace individually, will modify your .project file and only provides metrics up to the project level, but not the workspace level. – Korashen Jul 21 '14 at 12:03
-
1
-
3On Eclipse Mars 1, installing Metrics from the Help/Eclipse Marketplace failed - Metrics did not show up in Window/Show View/Other. Instead installing by adding it from http://metrics.sourceforge.net/update as described at http://metrics.sourceforge.net/ worked – Michael Feb 16 '16 at 08:24
Under linux, the simpler is:
- go to the root folder of your project
- use
find
to do a recursive search of *.java files - use
wc -l
to count lines:
To resume, just do:
find . -name '*.java' | xargs wc -l

- 361
- 2
- 7
-
2
-
And people are installing an eclipse plugin to load their memory. As if it was already not loaded too much. – neo7 Aug 05 '16 at 17:41
-
For eclipse(Indigo), install (codepro).
After installation:
- Right click on your project
- Choose codepro
tools --> compute metrics
- And you will get your answer in a Metrics tab as Number of Lines.
-
1This one is actually quite good! You should however fix the link as it gives a 404. – Lennert Nov 13 '13 at 13:39
-
Found this post that has a link to the latest version of codepro - and it works in Eclipse Oxygen: https://stackoverflow.com/questions/29390308/codepro-analytix-where-to-find-the-plugin-now-the-link-http-dl-google-com-ecl – Leonardo Alves Machado Jan 11 '18 at 20:19
Are you interested in counting the executable lines rather than the total file line count? If so you could try a code coverage tool such as EclEmma. As a side effect of the code coverage stats you get stats on the number of executable lines and blocks (and methods and classes). These are rolled up from the method level upwards, so you can see line counts for the packages, source roots and projects as well.

- 83,208
- 23
- 172
- 177
You could use a batch file with the following script:
@echo off
SET count=1
FOR /f "tokens=*" %%G IN ('dir "%CD%\src\*.java" /b /s') DO (type "%%G") >> lines.txt
SET count=1
FOR /f "tokens=*" %%G IN ('type lines.txt') DO (set /a lines+=1)
echo Your Project has currently totaled %lines% lines of code.
del lines.txt
PAUSE

- 2,057
- 1
- 15
- 26

- 41
- 1
I think if you have MyEclipse, it adds a label to the Project Properties page which contains the total number of source code lines. Might not help you as MyEclipse is not free though.
Unfortunately, that wasn't enough in my case so I wrote a source analyzer to gather statistics not gathered by other solutions (for example the metrics mentioned by AlbertoPL).

- 69,132
- 14
- 157
- 192
A very simple plugin for counting actual lines of source code is step counter eclipse plugin. Please download and try.
Place the downloaded jar file under eclipse\plugin folder and restart eclipse.
Rightclick and select step counter

- 631
- 6
- 14
You could use former Instantiations product CodePro AnalytiX. This eclipse plugin provides you suchlike statistics in code metrics view. This is provided by Google free of charge.

- 9,646
- 2
- 59
- 113