-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
macroURI="~./a/b/Filename.zul" will load file from fist meet /web/a/b/Filename.zul inside classpath.
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
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
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
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
@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:
your separate UI module.
your web app project.
After building the war-file. A look into it. 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
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.
Asked: 2008-11-12 15:04:42 +0800
Seen: 650 times
Last updated: Jul 30 '16