简体   繁体   中英

How to point to jdni.properties file to set properties in Java

I can use System.getProperties() method to set properties in Java.

System.getProperties().put("java.naming.factory.initial",
 "fr.dyade.aaa.jndi2.client.NamingContextFactory"); 
System.getProperties().put("java.naming.factory.host", "localhost");
System.getProperties().put("java.naming.factory.port", "16400");

How can I get the same effect by reading the properties stored in a file?

When I have a jdni.properties with the following content:

java.naming.factory.initial  fr.dyade.aaa.jndi2.client.NamingContextFactory
java.naming.factory.host localhost
java.naming.factory.port 16400

How can I teach Java to read them as properties? I use eclipse for development.

有一个现成的功能-Properties.load(InputStream inStream)

只需将其放在您的一个JAR文件的根目录中,或放在WAR文件的WEB-INF / classs中。

The jdni.properties should be in the class path. In eclipse, I had to use Advanced tab in Run Configuration/CLASSPATH to add the directory to be included as class path.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM