# Load package descriptor from imported module

aUser
113 4

Hello,

i have a webapp called test that imports a module called utilityModule using pom.xml like this:

<dependency>
<groupId>groupId</groupId>
<artifactId>utilityModule</artifactId>
<version>1.0.0</version>
</dependency>


Inside this utilityModule i have a package descriptor at this location:

src/main/resources/web/dir1/dir2/js/utilityPackage/utilityPackage.wpd

and a .zul page at this location:

src/main/resources/web/dir1/dir2/main.zul

Inside the main.zul page from the utilityModule i'm calling a script and i need to import this utilityPackage but i can't easily reference it..

I can't use this because it tries to reference the file from the test webapp

<script>
....
}
</script>


and i can't reference it neither this way as suggested here

<script>
....
}
</script>


Any help on how to reference the utilityPackage from main.zul?

Thank you

delete retag edit

Sort by » oldest newest most voted

cor3000
5673 2 7

ok good to know the mechanism works using

/web/js/[yourpackage]/zk.wpd

That's let's say level 1. And can be loaded using zk.load('yourpackage', callback). Since ZK uses this mechanism internally also for nested modules this functionality is also available to you. Still the path in your source files needs to start with /web/js followed by your package folders, then zk.wpd

e.g.:

/web/js/dir1/dir2/somepackage/zk.wpd

<package name="dir1.dir2.somepackage" language="xul/html">
</package>


you'll then be able to load this package via zk.load('dir1.dir2.somepackage', callback).

If you provide multiple file with the same folder/names it depends on the java classloader which resource is found first and loaded. You have to avoid this if you want reliable/predictable wdp loading.

cor3000
5673 2 7

I can't use this because it tries to reference the file from the test webapp

It is expected that all module resources are loaded via the webapp that includes them. The code you tried can't work for several reasons:

<script>
....
}
</script>


Correct observation it doesn't work for several reason:

1) it's syntactically wrong, it's not even correct javascript

2) it is not following the API docs on zk.load - the zk.load function has 2 arguments, a package name and callback function to be called when the package is loaded.

Correct syntax and api usage:

<script>
...
});
</script>


This will then load the package 'utilityPackage' using the following url inside your test webapp ...

http(s)://[yourserver]/test/zkau/web/[someid]/js/utilityPackage.wpd

... which will then try to find the corresponding zk.wpd file in your classpath under (also in your utilityModule.jar):

web/js/utility/zk.wpd

The related source location in your module project is:

src/main/resources/web/js/utility/zk.wpd

3) you placed your file into unexpected subfolders (dir1/dir2) and the wrong file name utilityPackage.wpd instead of zk.wpd (we had all this covered in a your previous question ... no need to change this pattern).

src/main/resources/web/dir1/dir2/js/utilityPackage/utilityPackage.wpd

src/main/resources/web/js/utilityPackage/zk.wpd

Important are the first two folders web/js ... and the name zk.wpd.

(Again can only remind you that we offer dedicated support to help more efficiently to avoid these kind of confusion from the start.)

aUser
113 4

I need to apologize for this question, i made several mistakes writing it even though the code i'm using respects the correct syntax for the package loading and zk.wpd filename.

I tried to put my folder with the needed files under

src/main/resources/web/js/utilityPackage/zk.wpd


in the imported module and it worked. That was just about it, putting the folder on that path. But is it always necessary? I mean can't i reference a file that has a path in my module as

src/main/resources/web/dir1/dir2/js/utilityPackage/zk.wpd


?

I didn't find the documentation for this structured way to organize files inside a webapp on zk documentation, can i read it somewhere?

If i have the correct path for both my webapp and a module i import, say for example again this path

src/main/resources/web/js/utilityPackage/zk.wpd


Will this file be red from the webapp or the module?

Thank you

aUser
113 4

Ok, it's very clear, however in the docs you linked i could only see a reference to the path web/js/..., quoting:

WPD must be named zk.wpd and placed in the same directory as the widget classes. For example we would place it under web/js/com/foo.

I'm wondering if the path web/js/ is related to ZK's standard or maybe Maven related? If it is ZK's related, are there other "standard" paths that i should follow in order to load other kind of files correctly?

Thanks

yes that's a ZK convention, ZK's classpath resources go below /web and ZK's js packages below /web/js maybe there are others right now I don't recall which ...

this is the java implementation class https://www.zkoss.org/javadoc/latest/zk/org/zkoss/web/util/resource/ClassWebResource.html

( 2021-01-19 18:34:43 +0800 )edit

here a related config option mentioning this internal mechanism https://www.zkoss.org/wiki/ZKConfigurationReference/zk.xml/TheLibraryProperties/org.zkoss.web.util.resource.dir (don't use it, it's much more flexible work inside src/main/resources/web)

( 2021-01-19 18:43:20 +0800 )edit

Thank you, gonna read some docs, i'll keep using src/main/resources/web as you suggest since i don't think i need to use that org.zkoss.web.util.resource.dir yet

( 2021-01-19 21:32:41 +0800 )edit

yes since you can only specify one value for org.zkoss.web.util.resource.dir I'd keep it available in case you need to apply some kind of hot patch in an emergency

( 2021-01-20 09:23:32 +0800 )edit
[hide preview]