Add a properties file to IntelliJ's classpath

后端 未结 10 2308
栀梦
栀梦 2020-11-28 19:20

I\'m running a simple Java program from the IntelliJ IDE using the Run->Run menu. It works fine. Now I want to add log4j logging.

I added a resources folder under my

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 20:07

    I spent quite a lot of time figuring out how to do this in Intellij 13x. I apparently never added the properties files to the artifacts that required them, which is a separate step in Intellij. The setup below also works when you have a properties file that is shared by multiple modules.

    • Go to your project setup (CTRL + ALT + SHIFT + S)
    • In the list, select the module that you want to add one or more properties files to.
    • On the right, select the Dependencies tab.
    • Click the green plus and select "Jars or directories".
    • Now select the folder that contains the property file(s). (I haven't tried including an individual file)
    • Intellij will now ask you what the "category" of the selected file is. Choose "classes" (even though they are not).
    • Now you must add the properties files to the artifact. Intellij will give you the shortcut shown below. It will show errors in the red part at the bottom and a 'red lightbulb' that when clicked shows you an option to add the files to the artifact. You can also go to the 'artifacts' section and add the files to the artifacts manually.

    enter image description here

提交回复
热议问题