find unused properties in eclipse
I开发者_Go百科 have set of classes and (struts)jsp files which uses Message bundle. I want to find properties which are not used in project.One simple way would to search for each property (in given project) and if 0 result, delete it.
In eclipse there is a function like
Source > Find Broken Externalized Strings
I don't think it works. Not sure what its for. I get message
"no nls property files with corresponding accessor of class found in selection"
It seems like Eclipse expects to find the class that it generates in the "Externalize Strings..." command:
package com.foo.bar;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "com.foo.bar.messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
Actually, after digging a little deeper, I found that Eclipse really wants the following:
private static final String BUNDLE_NAME = "com.foo.bar.messages"; //$NON-NLS-1$
public static String getString(String key) {
...
}
The package "com.foo.bar" must contain the file "messages.properties". You can run "Find Broken Externalized Strings" on any source file (or on the package) that you add these lines to.
精彩评论