Using the properties file

I am creating a properties file to connect to the database. I gave the path to the file, and I save the properties using the function:

 public void setProperty(String key, String value) {
    properties.setProperty(key, value);
}

I set the following properties:

"url","jdbc:mysql://localhost:3306/";"dbname","example";"user", "postgres";"Pass","123";

My question is, when I use my application on another system, how this property file can be useful (in fact, I went through the "properties file in java", but could not understand how they are used).

In the new system, the username and password will be different, so how can this file be useful?

+5
source share
2 answers

In the new system, the username and password will be different, so how can this file be useful?

This is useful because the file may be different on different systems. By placing system-specific parts in a file that can be modified on different systems, you do not have to write different Java codes for each other system.

, , , :

  • ,
  • , ,
  • , .

, , . . java.util.Properties .

+4

, , jar. - :

  • , . Maven , maven-assembly-plugin
  • , , /src/resources/config ()
  • ( zip ), /src/resources/config zip config - /config zip . /config , , maven-jar-plugin maven-dependency.
  • jar zip, /lib ( maven-dependency)

zip , , :

/

/config

/bin

/lib

<main jar file with manifest - the manifest contains all the classpath info - this info is automatically generated by the maven plugins>

, , . , .

0

All Articles