简体   繁体   English

如何使用 gradle 将外部文件添加到 jar?

[英]How to add an external file to the jar using gradle?

Until recently I was just using a simple Java project.直到最近我才使用一个简单的 Java 项目。 I recently decided to upgrade it to use a gradle wrapper and Netbeans 12, but now the program is unable to detect the beep3.wav file .我最近决定升级它以使用 gradle 包装器和 Netbeans 12,但现在程序无法检测到beep3.wav 文件

Earlier, I had managed to get the project to automatically embed the wav file into the jar.早些时候,我设法让项目自动将 wav 文件嵌入到 jar 中。 But now the project properties do not have any such option, which I assume is because the embedding has to be done via gradle.但是现在项目属性没有任何这样的选项,我认为这是因为嵌入必须通过 gradle 完成。 Even though the file is visible as part of the project, I couldn't see it in the jar when I opened the jar using archive manager.即使该文件作为项目的一部分可见,但当我使用归档管理器打开 jar 时,我在 jar 中看不到它。
在此处输入图像描述

I've seen this , this and many other pages, but none of them have info on adding files to the jar, so I'm assuming I'm looking for the wrong info.我已经看过这个这个和许多其他页面,但没有一个有关于将文件添加到 jar 的信息,所以我假设我正在寻找错误的信息。

Could you help with this please?你能帮忙吗? I just need to get that wav file to automatically get inserted into the jar when I build the project.我只需要在构建项目时将该 wav 文件自动插入到 jar 中。

You just add your files to src/main/resources and they end up in your jar.您只需将文件添加到src/main/resources ,它们最终会出现在您的 jar 中。

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

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