JPackage – 我的Windows应用程序镜像应该放在哪个位置resources文件夹?

huangapple go评论151阅读模式
英文:

JPackage- Where should I put resources folder for my Windows app image?

问题

在我制作的一个应用程序中,我将资源文件放入一个名为YoutubeAudioAutoDownloader-resources的文件夹中,并确保当我将该文件夹放在我的应用程序的.jar文件旁边时,它能够正常工作。

当我使用以下命令代码使用jpackage制作一个exe安装程序时:(由于我的糟糕目录安排,抱歉代码有点乱,我只想强调--type--resource-dir选项)

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

我有一个问题:

**我应该把我的YoutubeAudioAutoDownloader-resources文件夹放在哪里?**是放在我的应用程序图像文件夹的app文件夹中吗?还是因为有了--resource-dir选项,我不需要做任何操作?(我不确定我是否正确了解了该选项)

英文:

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-diroption? (I'm not sure whether I even know correctly about the option)

答案1

得分: 1

--resource-dir参数在jpackage中用于更改应用程序EXE的资源,如图标等,但听起来实际上您想要通过myClass.getClassLoader().getResourceAsStream("somerespath.xyz")访问自己类中的本地资源。

我认为JDK 14的jpackage没有提供一种指定本地资源目录并添加到运行的jpackage EXE类路径的方法。但它确实会添加JAR文件,因此如果您将所有资源目录与一个简单的Java类(比如MyNewClass)一起打包到一个JAR文件中,您可以使用以下方式定位资源:

MyNewClass.class.getClassLoader().getResourceAsStream("pathto/aresource.xyz");

这个新的JAR文件需要与其他JAR文件一起,所以它会被--input "%~dp0packaging\jar"捆绑在一起,然后每个启动器EXE的app/xyz.cfg的类路径字段应该引用额外的资源JAR文件。

英文:

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.

huangapple
  • 本文由 发表于 2020年8月31日 20:08:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63670541.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定