How to install JSF message package outside WAR?
Two ways:
change text and update messages in the application without restarting the application
Changing the text will be trivial. However, the update is not trivial. Mojarra internally caches it aggressively. This must be taken into account if you want to go on the way 1. Arjan Tijms published a special Mojarra trick to clear its internal resource cache in this related question: How to reload a resource in a web application?
If the text change occurs in the web application itself, you can simply clear the cache in the save method. If the text change can occur from outside, you need to register the file system viewer to listen for the changes (the tutorial is here ), and then either clear the beam cache for path 1 or reload 2 inside handleGetObject() again.
has a default pool in WAR that is overwritten by an external package
When loading from the path class, the default behavior is the other way around (resources in WAR have a higher priority when loading), so this will definitely scratch path 1 and leave us with method 2.
The following is an example of launch 2. This assumes that you are using resource resource packages with the base name text (that is, without a package) and that the external path is in /var/webapp/i18n .
public class YourBundle extends ResourceBundle { protected static final Path EXTERNAL_PATH = Paths.get("/var/webapp/i18n"); protected static final String BASE_NAME = "text"; protected static final Control CONTROL = new YourControl(); private static final WatchKey watcher; static { try { watcher = EXTERNAL_PATH.register(FileSystems.getDefault().newWatchService(), StandardWatchEventKinds.ENTRY_MODIFY); } catch (IOException e) { throw new ExceptionInInitializerError(e); } } private Path externalResource; private Properties properties; public YourBundle() { Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); setParent(ResourceBundle.getBundle(BASE_NAME, locale, CONTROL)); } private YourBundle(Path externalResource, Properties properties) { this.externalResource = externalResource; this.properties = properties; } @Override protected Object handleGetObject(String key) { if (properties != null) { if (!watcher.pollEvents().isEmpty()) {
To run it, register as below in faces-config.xml .
<application> <resource-bundle> <base-name>com.example.YourBundle</base-name> <var>i18n</var> </resource-bundle> </application>
source share