Extract all string from a java project

Eclipse does do this automatically. Right-click the file, choose "Source", then "Externalize strings"

This doesn't do exactly what you requested (having the strings in a Constants.java file as Strings) but the method used is very powerful indeed. It moves them into a properties file which can be loaded dynamically depending on your locale. Having them in a separate Java source file as you suggest means you'll either have ALL languages in your application at once or you'll ship different applications depending on locale.

We use it for our applications where even the basic stuff has to ship in English and Japanese - our more complicated applications ship with 12 languages - we're not a small software development company by any means :-).

If you do want them in a Java file, despite the shortcomings already mentioned, it's a lot easier to write a program to morph the properties file into a Java source file than it is to try and extract the strings from free-form Java source.

All you then need to do is modify the Accessor class to use the in-built strings (in the separate class) rather than loading them at run time.


To complete Peter Kelley answer, you might consider for eclipse IDE the AST solution.

You might then write an AST program which parse your source code and does what you want.

A full example is available in this eclipse corner article, also more details in the eclipse help.
And you can find some examples in Listing 5 of the section "Implementation of in-place translation" of Automating the embedding of Domain Specific Languages in Eclipse JDT, alongside multiple examples in GitHub projects.