Fairly new to Wicket so excuse my ignorance.
I have a Wicket app...starts with WicketApplication.class
I have a WicketApplication.properties
file to load some values. The properties file sits next to the class file (same package). Works fine, no issues.
Now, I would like to move the properties file outside the application WAR/JAR. Exported the app as a WAR to run on Tomcat. I have create aa folder called properties
under tomcat root & moved WicketApplication.properties to this directory. Added the following to init() method in WicketApplication.class...
String realPath = getServletContext().getRealPath("/");
realPath = realPath.replaceAll("\\\\", "/");
if (realPath.toUpperCase().indexOf("WEBAPPS") != -1) {
String newRes = realPath.substring(0, realPath.toUpperCase().indexOf("WEBAPPS") -1);
System.out.println (newRes + "/properties");
getResourceSettings().getResourceFinders().add(new Path( newRes + "/properties"));
}
I get an exception thrown.
How do I "externalise" the properties file?
Also, if I could take one step further, how do I map a properties file name to class name..it, myapplication.properties -> WicketApplication.class
Thanks in advance.
You need to add new IStringResourceLoader with application.getResourceSettings().getStringResourceLoaders().add(...)
. See https://github.com/apache/wicket/blob/515e2be2a5301f5caf7b1baee4a593d21c20e275/wicket-core/src/main/java/org/apache/wicket/settings/ResourceSettings.java#L220-L224 for the default ones.
IResourceFinder
should be used when you want to add custom location for your HTML files.
There is no way to map myapplication.properties
to WicketApplication.class
. By adding an additional IStringResourceLoader you just tell Wicket to search in yet another place.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.