在intellij中为java项目添加资源 [英] adding resources in intellij for java project
问题描述
我有这样的项目结构:
src
|-main
|-java
|-com.abc.xyz
|-Login.java
I必须向此添加资源文件并使用
I have to add a resource file to this and read the resource with
nputStream is = getClass().getResourceAsStream("launchers.properties");
这是空的。
In intellij我无法在src / main下为 resources
文件夹添加一个新包,所以
表示项目结构如下所示。如何将 launchers.properties
资源文件导入项目?
In intellij I am not able to add a new package under src/main for resources
folder so
that the project structure looks like this. How can I the launchers.properties
resource file into the project?
src
|-main
|-java
|-com.abc.xyz
|-Login.java
|-resources
|-com.abc.xyz
|-Login
|-launcher.properties
我试过@maba建议的解决方案但仍然无效
I tried the solution suggested by @maba but still not working
推荐答案
launcher.properties
不应位于名为 Login $ c的文件夹下$ C>。它应该直接放在
src / main / resources / com / abc / xyz
文件夹中。
The launcher.properties
should not be under a folder called Login
. It should be placed directly in the src/main/resources/com/abc/xyz
folder.
这真的很简单,但如果资源文件夹没有标记为来源文件夹,那么这可能是问题所在。
It is really as simple as I said but if the resources folder is not marked as a sources folder then this may be the problem.
这是初始课程和设置:
现在创建资源文件夹:
这个新创建的文件夹应自动标记为来源文件夹,如果是蓝色标记的话它是。否则你必须手动标记:
This newly created folder should be automatically marked as a sources folder and if it is blue color marked then it is. Otherwise you'll have to mark it manually:
现在你可以添加包了:
现在您可以将文件添加到其中:
And now you can add the file to it:
重新运行应用程序不会给你任何 null
值:
And rerunning the application will not give you any null
value back:
包视图肯定会显示 launchers.properties
文件:
And the package view will surely show the launchers.properties
file as well:
这篇关于在intellij中为java项目添加资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!