Recently packaged the code into a jar package, for information on how to handle reading the configuration file is hereby recorded.
The directory structure is as follows
- Out.properties
- A.jar
- -com
- -A.class
- -in.properties
As shown above, Out.properties is in the A.jar package in the same file directory;
The in.properties is inside the A.jar package.
About A.class How to read a configuration file inside a jar or outside the jar,
As shown below:
Java code
- FileInputStream inputStream1 = new FileInputStream ("out.properties");
- InputStream inputStream2 = A.class.getresourceasstream ("/in.properties");
In addition, the log4j configuration file log4j.properties can be placed in the same directory as the jar package and will automatically take effect.
If the XML file and the jar package are in the same directory, then there is no difference in classpath. Can read directly, load
How classes in a jar package read configuration files inside and outside the package