ICE Read Properties file
It’s easy to change properties if they are set in Properties files. Properties file contains many name–value pairs with each pair on a separate line. When any empty lines and lines consisting entirely of white space those characters are ignored. If you want to comment any properties then use # character introduces as comment in the file.
This demo is continuation of ICE Hello World tutorial where we put ICE adapter and end point information inside the code. Using property file we will keep these value outside and read dynamically and set in system path after loading property file.
- Project structure with properties file:
- configuration.properties: We are setting end point parameter here and read in client and server file:
- LoadReadPropertyFile.java class to load and set property value in system path:
- Please copy all configuration and setting from ICE Hello World tutorial and little modification done in Server.java and Client.java class to read and set end point value from property file:
- You could load property file by directly setting its fully qualified path in the code but this will make dependency on the code, every time you change path of the file you will have to recompile class. To avoid this we will set file path as VM argument on both Server and Client class and read its value. I have set file path in VM argument in eclipse as below. If you are using command prompt to run this then pass same from command prompt:
- Run client server separately as you ran in this tutorial you will see below output:
- For more information please refer ICE manual here
Download project: ICEHelloWorld