views:

360

answers:

2

It looks like the "Externalize Strings" feature takes everything, makes a Messages class, and a .txt file in which to store the Strings themselves. This is interesting, but I've got another way to store constants:

public final class Constants {
    //for parsing commands
    public static final String REGEX_COMMAND = "(\\w*) *= *\"(.*)\""; //Regex for a command from a data file
    //etc
}

Is there any way to get Eclipse to automatically move Strings and other values to here for me?

+1  A: 

Select a literal, right click, Refactor -> Extract Constant... proceed with the wizard.

Asaph
yes, but that's only within the class itself, not to another Constants class in the same package.
Rosarch
After you've extracted the constant, you can select Refactor → Move.
gustafc
ok, now is there a way to do that for every literal in the package, at once?
Rosarch
A: 

There is no way to move the strings automatically. If you need to move several String constants by hand, the most convenient way to do that is through drag and drop: select the strings you want, and drag them to your Constants class.

Oleg Ryaboy