Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include directory from resources while compiling native Image via gluon client maven plugin #3092

Closed
rnayabed opened this issue Dec 29, 2020 · 7 comments

Comments

@rnayabed
Copy link

I wrote a custom alert/combobox implementation for my project. Could not
use Gluon Mobile because its integrated tightly with our custom Theme
API. It works now!!

However, I have a small issue. My project root currently looks like this

root

 - src

 - resources

     - default/

         - config.xml

         - Themes/

         - Profiles/

         - Icons/

     - style.css

     - Roboto.ttf

When the config.xml file isnt found on local disk, the program just
copies all the contents of the default directory to the disk.

I am using gluon client and their maven plugin
However, when i try to get Main.class.getResource("default/").toURI()
it returns a nullpointer. i added -H:IncludeResources='*/*.*' to
<nativeImageArgs> but it doesnt work. I also tried adding that under
<resourcesList> but that too did not work.

Any leads on how I can embed all the directories/files/ everything from
the resources folder onto the native image

GraalVM Version : 20.2.0
Platform : x64 Linux

@kkriske
Copy link
Contributor

kkriske commented Dec 30, 2020

The pattern passed to IncludeResources is a regex, see the docs: https://github.com/oracle/graal/blob/master/substratevm/Resources.md

So the "regex" */*.* simply does not what you think it does. To include everything in the default dir, adding default/.* should normally do the trick.

As for the resourceList option of the gluon maven plugin, it writes the pattern to a resources-config.json file, you have exactly the same problem there.

Small note of caution: the patterns count towards all files, not only files in the resource directory, as the content of src and resource directories normally get merged in jars, so adding .* will add everything, including class files, to resources, which you don't want.
Just be careful with broad wildcards.

@rnayabed
Copy link
Author

@kkriske i tried -H:IncludeResources='Default/.*' but it did not work as well :(

The line new File(Main.class.getResource("Default/").toURI()) is causing NullPointerException

@kkriske
Copy link
Contributor

kkriske commented Dec 30, 2020

What I think that's happening, without having the stacktrace: You are looking up a directory, which is not a resource, so getResource returns null. Looking up a file in the directory should work.

Walking through resources as a directory structure is not (yet) supported, as mentioned here: #2762 under Improve support for resource registration

@rnayabed
Copy link
Author

@kkriske yes, looking up a file inside the resources folder work, but looking up directory doesnt. Ill try something like this new File(Main.class.getResource("Default/config.xml").toURI()).getAbsoluteFile().getParentFile()

@rnayabed
Copy link
Author

@kkriske so now after pointing to the file and then going up one direcotry, it throws a java.lang.IllegalArgumentException: URI is not hierarchical :/

@rnayabed
Copy link
Author

I think i need to zip the folder into a zip, and then unzip it

@rnayabed
Copy link
Author

@kkriske I think I discovered an issue

class.getResourceAsStream("filename") works. But class.getResource("filename") returns resource:<file location>, which doesn't work if I want to read a file, copy it somewhere.

Closing it because in the end, what the workaround was to zip the directory, and then extract it to a location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants