Add properties file to build path of runnable jar

后端 未结 7 1638
無奈伤痛
無奈伤痛 2021-01-07 02:48

is it possible to add to the classpath of a runnable jar file some properties file? I tryed these solutions solutions:

  1. running the executable file using the

7条回答
  •  囚心锁ツ
    2021-01-07 02:55

    You have to reference the .properties file in your class file relative to the .jar file location. The classpath seperators are different for Windows (semicolon) and Unix environments (colon).

    For windows

    java -classpath .;prop_dir; -jar Runnable.jar (In your Class file, the properties file should be accessed by relative URl from classpath say "prop_dir/prop1.properties")

    For Unix env

    java -classpath .:prop_dir: -jar Runnable.jar (In your Class file, the properties file should be accessed by relative URl from classpath say "prop_dir/prop1.properties")

    Code:

    enter image description here

    Output:

    enter image description here

提交回复
热议问题