In a application I made, I put my resources files to a folder(named YoutubeAudioAutoDownloader-resources
) and made sure it worked when i put the folder next to .jar file of my app.
And When I use jpackage
to make a exe installer with following cmd code: (sorry for dirty code because of my terrible directory arrangement, only part I want to stress is --type
and --resource-dir
options)
set jh=D:\development\jdk-14\bin
set appname=YoutubeAudioAutoDownloader v1.2.2
pushd %jh%
jpackage --type app-image --name "%appname%" --input "%~dp0packaging\jar" --dest "%~dp0packaging" --main-jar "YoutubeAudioAutoDownloader v1.2.2.jar" --main-class "com.awidesky.YoutubeClipboardAutoDownloader.Main" --resource-dir "%~dp0release.v1.2.1\YoutubeAudioAutoDownloader-resources" --icon "%~dp0icon\icon.ico
pause
I got question:
Where should I put my YoutubeAudioAutoDownloader-resources
folder? in app
folder of my app image folder? or I don't have to do because of --resource-dir
option? (I'm not sure whether I even know correctly about the option)
The --resource-dir
parameter in jpackage is for changing the resources of the application EXE such as icons etc but it sounds like you actually want local resources accessed by your own classes with myClass.getClassLoader().getResourceAsStream("somerespath.xyz")
.
I don't think JDK14 jpackage gives a way to specify a local resources directory to add to the classpath of the running jpackage EXE. But it does add jars so if you bundle all of your resources directory into a jar along with a simple Java class say MyNewClass
you could locate the resources with:
MyNewClass.class.getClassLoader().getResourceAsStream("pathto/aresource.xyz");
This new jar would need to be with your other jars so it is picked up with --input "%~dp0packaging\jar"
and then the classpath field of each launcher EXEs app/xyz.cfg
should refer to the extra resources jar.