0

load a zul from inside a jar

asked 2008-11-12 15:04:42 +0800

ManicMiner gravatar image ManicMiner
24

it is possible to load a zul file from inside a jar file?

i want to load a file from inside a jar with the macroURI path, but i dont know if it is possible and the path you must specify.

if i have a zul file inside a package like "package.subpackage.Filename.zul", inside the "library.jar" archive, when i try to load using macroURI="package/subpackage/Filename.zul", i get <org.zkoss.zk.ui.UiException: Page not found> exception when running the page (using JBoss 4.2.2GA server).

it is possible such way of load? is there any error in the path?

Thanks in advance

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2008-11-13 02:32:11 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

updated 2008-11-13 02:41:03 +0800

macroURI="~./a/b/Filename.zul" will load file from fist meet /web/a/b/Filename.zul inside classpath.

link publish delete flag offensive edit

answered 2008-11-13 17:30:26 +0800

ManicMiner gravatar image ManicMiner
24

sorry dennis but don't understand your reply.....

i am trying to load a zul file using macroURI="~./WEB-INF/lib/package/filename.zul", but don't work....

the jar file is inside the "/WEB-INF/lib" directory, but the "Page not found" nightmare continues....

could you be more specific in your example --may be a real example?--

regards

link publish delete flag offensive edit

answered 2008-11-14 00:52:55 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

a simple example, if you put a yyy.zul inside 'kkk.jar/web/a/b' file (this jar file should local at /WEB-INF/lib )
then you can use "~./a/b/yyy.zul'
start with "~./" means search form class loader's resource.

/Dennis

link publish delete flag offensive edit

answered 2008-11-14 16:53:58 +0800

ziccardi gravatar image ziccardi
321 7

Or, (if for some reason you can't use dennis' solution) you can use Executions.createComponentsDirectly(reader, extension, parent, Map arg).

Simply, use ClassLoader.getResourceAsStream, to get the zul input stream.
Instantiate a reader on that stream, and then:

Executions.createComponentsDirectly(yourZulReader, "zul", null, null);

Regards,
Massimiliano

link publish delete flag offensive edit

answered 2009-02-08 14:27:51 +0800

InfoSec812 gravatar image InfoSec812
96

I wrote a quick HOWTO in the Tricks section of the Wiki on more specifics of how to accomplish this, including example code. The link is :

http://docs.zkoss.org/wiki/ZK/How-Tos/Concepts-and-Tricks#Load_a_ZUL_file_from_classpath_or_JAR

link publish delete flag offensive edit

answered 2014-05-30 12:36:26 +0800

rahult gravatar image rahult
1

@InfoSec812 -- The link you shared does not seems to contain the valid information on the topic.

link publish delete flag offensive edit

answered 2014-05-30 12:38:07 +0800

rahult gravatar image rahult
1

@Dennis, Can you point me to a doc page, explaining how to use macroURI you are mentioning here.

link publish delete flag offensive edit

answered 2014-06-04 08:43:25 +0800

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

updated 2014-06-04 08:47:32 +0800

@rahult,

you can load a zul file in an other jar-file with the '~./' prefix before the path. ZK than search in the classpath for the zul-file. Therefore the searched zul-file must be inside a jar-file who is placed in the /WEB-INF/lib folder of your main web application.

Three images should show that:

  1. your separate UI module. image description

  2. your web app project. image description

  3. After building the war-file. A look into it. image description Where zkboost-module1-1.....jar is the jar file with the zul-files in it that we want to load.

java call:

Map<String, Object> map = new HashMap<String, Object>();
map.put("item", new Customer());
Executions.createComponents("~./zul/pages/customer/customerCRUD.zul", null, map);

best Stephan

link publish delete flag offensive edit

answered 2016-07-30 14:39:09 +0800

sirlordt gravatar image sirlordt
16 1

The problems is you final file .jar it not have the .zul file inside.

You must copy the .zul file in src/main/resources/web maven copy the files to inside .jar, later is available for load using but "~./" prefix, remember use create the folder called web.

Example:

src/main/java/   
  mypackage/
    myanotherpackage/
      classforcreatethecomponents.java <--.createComponents( "~./myscreen.zul", args );

src/main/resources/
  web/ <-- Required folder by zk to work 
    myscreen.zul

If you need the zul inside from the package you need force to maven include the .zul files in the final .jar

Example:

src/main/java/
  web/ <-- Required folder by zk to work 
    mypackage/
      myanotherpackage/
        classforcreatethecomponents.java <--.createComponents( "~./mypackage/myanotherpackage/myscreen.zul", args );
        myscreen.zul

Note the web folder at begin of package/folders this required by zk, to map the resources from .jar file

In the pom.xml from you project put this in the build section.

<build>

 <resources>

   <resource>

      <directory>src/main/java</directory>

      <includes>

        <include>**/*.zul</include> <!--Force maven to copy the .zul files to .jar-->
        <include>**/*.png</include>
        <include>**/*.jpg</include>

      </includes>

      <excludes>
        <!-- 
        <exclude>**/*test*.*</exclude>
        -->
      </excludes>

    </resource>

  </resources>

  .... <!-- Another stuff from you pom.xml -->     

</build>

Check the final .jar contains the .zul files in correct path, remember the .jar file is a .zip you must check using winzip or winrar and navigate in internal structure.

This fix the problems loading .zul from inside .jar file at runtime, you can also load images from inside the .jar and show in you screens web pages, inside the .zul you can especify use the "~./" prefix and work for images and another resources, using the same logic struct from .zul resource.

Example:

src/main/resources/
  web/
    images/
      net.png     

<button label="Left" image="~./images/net.png" width="125px"/>

I using eclipse ide luna and maven internal from eclipse.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2008-11-12 15:04:42 +0800

Seen: 650 times

Last updated: Jul 30 '16

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