1

Share i3-labels between apps without copying

asked 2015-03-31 20:09:33 +0800

KlausWr gravatar image KlausWr
37 5

updated 2015-03-31 20:10:04 +0800

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?

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
2

answered 2015-04-02 08:51:42 +0800

echarish gravatar image echarish flag of Japan
1809 7
http://jp.linkedin.com/in...

updated 2015-04-02 08:53:48 +0800

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.

image description

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.

link publish delete flag offensive edit

Comments

1

So, after moving zk-labels.properties to src/metainfo it workd like a charm. Don't know if only this made the trick, but I am happy for now. Thanks a lot.

KlausWr ( 2015-04-02 20:04:52 +0800 )edit

Glad that it worked, and sorry that i forgot to mention it before to put your files in metainfo folder (My bad).. but all's good that ends good ;)

echarish ( 2015-04-03 05:15:45 +0800 )edit
2

answered 2015-04-01 02:58:23 +0800

echarish gravatar image echarish flag of Japan
1809 7
http://jp.linkedin.com/in...

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.

link publish delete flag offensive edit

Comments

1

So this really means that I can address everything with the classpath prefix ~./ ? Each kind of resource? That would be cool! I love it.

KlausWr ( 2015-04-01 06:22:47 +0800 )edit
1

Yes, that's exactly what it is. I love it too as it solves problems of doing everything in one place, you can simply make separate modules and have separate files for easy maintenance

echarish ( 2015-04-02 01:46:46 +0800 )edit
2

answered 2015-04-01 03:10:07 +0800

echarish gravatar image echarish flag of Japan
1809 7
http://jp.linkedin.com/in...

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

link publish delete flag offensive edit
1

answered 2015-04-01 10:09:04 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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

link publish delete flag offensive edit

Comments

Cool. For those various zk-label.properties in module*.jar: Do you need seperate <label-location>~./zk-label.properties</label-location> entries (with a distinct unique inner path) in zk.xml or does it load all those zk-label.properties at once?

KlausWr ( 2015-04-01 10:32:53 +0800 )edit
1

It's up to you, where you keep them, as long as they are named zk-label_*.properties, * is for various language versions, ZK will access them from classpath and load them all for you.

echarish ( 2015-04-02 01:58:19 +0800 )edit

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 )edit
1

Are 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

Yes, I can load zul's and images, but the labels are not loaded.

KlausWr ( 2015-04-02 08:16:04 +0800 )edit
1

answered 2015-04-02 10:30:23 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2015-04-02 10:43:49 +0800

@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.

link publish delete flag offensive edit

Comments

It's now working after doing according to the hint of echarish. So I did not need to register ... but anyway buying your e-book is definitely one of th next things to do. Great work from what I took from your website!

KlausWr ( 2015-04-02 20:07:01 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-03-31 20:09:33 +0800

Seen: 41 times

Last updated: Apr 02 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More