Adding resources in IntelliJ for Maven project

后端 未结 7 1297
走了就别回头了
走了就别回头了 2020-11-28 07:36

I have a project structure like this:

src
 |-main
    |-java
       |-com.abc.xyz
          |-Login.java

I have to add a resource file to t

7条回答
  •  失恋的感觉
    2020-11-28 07:52

    As @maba pointed out, your properties file should be in the same package as your class for your code to work.

    So, you should have two files:

    • src/main/java/com/abc/xyz/Login.java
    • src/main/resources/com/abc/xyz/launcher.properties

    If IntelliJ is showing the resource or not is beside the question. What you need to do is check if the results are included in your target artefact.

    Do a build all in IntelliJ, open up the resulting WAR/JAR/EAR with your favorite ZIP viewer and browse into the "com/abc/xyz" folder. You should see both files there.

    • If they are, you are doing something wrong in your code. Check for typos, especially dots and spaces at the end or beginning (e.g. "launcher.properties[space]"), copy/paste the file name to make sure
    • If they are not there, your IntelliJ setup is wrong. Resources do not get included in your target build. Check online for tutorials how to do this with IntelliJ idea.

提交回复
热议问题