简体   繁体   English

在尝试创建 JAR 文件时,您应该将资源(即图像和声音文件)放在哪里?

[英]Where is the right way that should you put your resources (i.e Images and Sound files) when trying to create a JAR file?

I am using Intellij IDEA and whenever I build a JAR artifact it places itself on the productions folder.我正在使用 Intellij IDEA,每当我构建 JAR 工件时,它都会将自己放置在 productions 文件夹中。 When I try to run the JAR file some custom defined functions (ie setting Icons on Components and adding sounds) are missing, while running it on the Intellij's IDEA is functioning correctly.当我尝试运行 JAR 文件时,缺少一些自定义功能(即在组件上设置图标并添加声音),而在 Intellij 的 IDEA 上运行它时运行正常。 I know that it involves using getResourceAsStream method but is there some sort of right way to place external resources?我知道它涉及使用 getResourceAsStream 方法,但是有某种正确的方法来放置外部资源吗?

Additional questions I may add, where is the correct destination for placing the META-INF folder?我可能会添加其他问题,放置 META-INF 文件夹的正确目的地在哪里? Should I make a resource folder for all my external files?我应该为所有外部文件创建一个资源文件夹吗?

This is for Eclipse users, I believe the same thing can be accomplished in other IDE's relatively easily.这是针对 Eclipse 用户的,我相信在其他 IDE 中也可以相对轻松地完成同样的事情。

  • Create a resources folder创建资源文件夹
  • Put your non-code files in it将您的非代码文件放入其中
  • Use as "Source Folder"用作“源文件夹”

在此处输入图像描述

After creating the JAR, the contents of "resources" will be packed in the JAR.创建 JAR 后,“资源”的内容将被打包到 JAR 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM