XML Configuration: (notification.xml)
<?xml version="1.0" encoding="UTF-8"?>
<config>
<notification>
<server>Server</server>
</notification>
</config>
Code:
import org.apache.commons.configuration.XMLConfiguration;
try {
XMLConfiguration config = new XMLConfiguration(getClass().getResource("notification.xml"));
String server = config.getString("notification.server");
System.out.println(server);
}
catch(Exception e) {
e.printStackTrace();
}
Key:
- getClass().getResource() to get config file
- To get config value, use notification.server, not config.notification.server
沒有留言:
張貼留言