-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I learned from http://stackoverflow.com/questions/14808693/load-zul-from-jar how to load a zul from a jar. With this I have a way to share zul files and their controller classes between web apps withou having the need to copy (I hope so, but did not finally check yet).
BUT, what about sharing the language resources (like "i3-labels") or images, CSS, js?
Any idea?
Hello KlausWr
Have also checked if your zk-label file is available in jar file
Below is the image of java project that i refer in my Web project as you can see, my zk-label file on classpath, in my web project I do not ask ZK to load them explicitly , it does so by itself based on the file name, but if you do write in zk.xml and refer them than you will need to do it manually for all.
My advice will be to recheck the jar, go to cmd prompt and do
jar -xvf yourJarName.jar
and see if you properties files are being exported or not.
I think as long as your files remain on classpath and you refer them with correct path you can access anything from a jar's
I my project we have various label files for each module, these modules are separate java projects with each maintaining there own labels, and then they get referred in the main web project as jar's and i am not facing any problem in loading labels or images or css. the trick is to keep everything available at classpath and follow the file naming convention specified by ZK for labels files and ZK will do the remaining magic.
Below are the links which explain more about labels and separating them into separate files in separate modules
http://books.zkoss.org/wiki/ZKDeveloper'sReference/Internationalization/Labels#LoadingLabelsfromMultipleResources
http://books.zkoss.org/wiki/ZKDeveloper'sReference/Internationalization/Labels
In ZKBoost i do exactly what echarish mentioned.
The trick is using '~./' for searching the files in the classpath. In my case where i build the modules as separated jars i load the zul files in the same manner.
myApp.war
WEB-INF/lib/module1.jar (inlude: zk-label.properties + *.zul )
WEB-INF/lib/module2.jar (inlude: zk-label.properties + *.zul )
WEB-INF/lib/module3.jar (inlude: zk-label.properties + *.zul )
best Stephan
I tried ALL ways I could imagine ... but could NOT load my zk-label.properties from classpath. Neither implicitely by name (while not mentioned in zk.xml) as well as using label-location in zk.xmk (which reports an "not found" error in startup log). Please help!
KlausWr ( 2015-04-02 06:33:06 +0800 )editAre you able to load other resource from jar like zul etc., Please check if the jar on the classpath actully contains the resources by unpacking the war and than the jar, sometimes what we think should be on the classpath doesn't get packed in jar's so recheck it.
echarish ( 2015-04-02 07:06:01 +0800 )edit@KlausWR,
the labels MUST be registered by ZK. In my case i have a module initializer class in each of the modules wich registers the labels. (@see org.zkoss.util.resource.LabelLocator)
/**
* Constructor.
*
* @param _ctx Servlet context.
*/
public OXAdminModuleLabelLocator(ServletContext _ctx) {
this.ctx = _ctx;
}
@Override
public URL locate(Locale _locale) throws Exception {
/**
* The '/' before the resource name is needed for running in Tomcat 8.<br>
* Downwards compatible.
*/
if (_locale != null) {
return ctx.getResource("/zk-label" + "_" + _locale + ".properties");
} else {
return ctx.getResource("/zk-label" + ".properties");
}
}
Next as echarish mentioned you need a well folder structrue where the files are placed. src/main/resources/metainfo/zk-labelsdeDE.properties
The module initializer self is called automatically on application startup. (@see javax.servlet.ServletContainerInitializer )
best Stephan
Have a look on the ZKBoost sources + eBook. It's cheap for the very lot of stuff in it and can make your deveolpment easier.
Asked: 2015-03-31 20:09:33 +0800
Seen: 41 times
Last updated: Apr 02 '15
wrong valueException come in front of modal popup [closed]
Use parameters in a conditional @command
Problems with multiple press and onCtrlKey
MVVM @save on the fly [closed]
Unable to activate destroyed desktop
org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException
How to put a image or Letter over image on a specific XY Coordinate