Getting a list of all java packages in your workspace

Not exactly bnd / bndtools related, but useful in this context.

Use case

Recently I needed an overview about all package names we have in our workspace, to do some cleanup and check if package names conform to naming conventions etc.
So I wanted a sorted list where I can scroll through to get a quick overview.

cd myworkspace
find . -type f -name '*.java' -exec grep -h '^package ' {} + | sed 's/^package //' | sort -u  > allpackages.txt

The output is written to a file allpackages.txt. Duplicate lines are removed too.