Intellij资源不在构建工件中 [英] Intellij resources not in built artifact

查看:147
本文介绍了Intellij资源不在构建工件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个包含非标准图像和字体的.jar,我已将其添加到项目的资源文件夹中。我可以使用以下代码将它们加载到我的项目中。

I'm attempting to build a .jar that contains a non-standard images and fonts, which I have added to the resource folder in my project. I am able to load them into my project with the following code.

URL url = ClassLoader.getSystemResource("./some_font.ttf");

Font font = Font.createFont(Font.TRUETYPE_FONT, url.openStream());

虽然这在我在IDE中运行程序时有效,但是当导出的jar运行时它无法运行加载字体。

While this works when I run the program in the IDE, when the exported jar is run it is unable to load the font.

推荐答案

您可以在项目结构中创建自己的工件:

You can create you own artifacts in the project structure:

在那里你可以添加资源的目录内容夹。
按绿色加号并导航到您的文件夹并添加它。
然后,您可以单击build-> build artifacts - > build。
在我的情况下,jar是在./out/artifacts文件夹中创建的。

There you can add the directory contents of the resources folder. Press the green plus and navigate to your folder and add it. You can then click build-> build artifacts -> build. In my case the jar is created in ./out/artifacts folder.

这篇关于Intellij资源不在构建工件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆