gluonhq / gluonfx-maven-plugin

Plugin that simplifies creating native images for Java/JavaFX maven projects
BSD 3-Clause "New" or "Revised" License
189 stars 39 forks source link

Including assets from classpath via nativeImageArgs #445

Closed ianopolous closed 2 years ago

ianopolous commented 2 years ago

Thank you for your excellent work. I'm trying to include a folder of web assets in an android build (for retrieval via ClassLoader.getResourceAsStream()). It works fine if I use native-image directly outside of gluon to build a linux-amd64 image, but I can't seem to get the gluon build to pick up the folder. I'm using the following config:

<nativeImageArgs>
   <arg>-H:IncludeResources='webroot/.*'</arg>
</nativeImageArgs>

I've tried putting the webroot folder in the project root, and various sub folders related to android. None of them pick it up.

The project is here if you want to look: https://github.com/Peergos/mobile/tree/feat/local-server

Many thanks for any pointers on where to put it.

ianopolous commented 2 years ago

I've tried expanding the config to:

<nativeImageArgs>
     <arg>-H:IncludeResources='.*/webroot/.*$'</arg>
     <arg>-H:Log=registerResource:3</arg>
</nativeImageArgs>

And this confirms that some resources are being picked up with log lines like:

ResourcesFeature: registerResource: webroot/js/nacl.js

However other aren't, like webroot/index.html

It sounds like gluon is filtering on type. I think I need to add all the extensions to the resourcesList config. I got it all working in the end. With the following config:

                    <resourcesList>
                      <list>.*\\.bcmap$</list>
                      <list>.*\\.css$</list>
                      <list>.*\\.cur$</list>
                      <list>.*\\.eot$</list>
                      <list>.*\\.gif$</list>
                      <list>.*\\.html$</list>
                      <list>.*\\.ico$</list>
                      <list>.*\\.map$</list>
                      <list>.*\\.properties$</list>
                      <list>.*\\.svg$</list>
                      <list>.*\\.ttf$</list>
                      <list>.*\\.woff$</list>
                      <list>.*\\.woff2$</list>
                    </resourcesList>
                    <nativeImageArgs>
                      <arg>-H:IncludeResources='.*/webroot/.*$'</arg>
                    </nativeImageArgs>