0

I'm looking over sentry for java and it requires a properties file:

.level=WARN
handlers=net.kencochrane.raven.jul.SentryHandler
net.kencochrane.raven.jul.SentryHandler.dsn=https://<key>:<secret>@app.getsentry.com/<project>
net.kencochrane.raven.jul.SentryHandler.tags=tag1:value1,tag2:value2

It loads the file by: java -Djava.util.logging.config.file=/path/to/app.properties MyClass

I want to set the properties in java source; how do I do that?

It looks like I may be able to use the Properties class? Not sure though (Java isn't my primary language).

  • Do you want to set the properties into the file at runtime or to read the properties from the file at runtime? – Patrick Nov 13 '15 at 16:01
  • 1
    Please see if the link helps you [Stack Overflow](http://stackoverflow.com/questions/5189914/setting-system-property) – Ketan Nov 13 '15 at 16:01
  • this can also hepls you [writing to prop](http://www.mkyong.com/java/java-properties-file-examples/) – Patrick Nov 13 '15 at 16:02

2 Answers2

2

If you want to set property dinamically at runtime, you may use following code:

Properties props = null;
FileInputStream fis = null;
String propFile = "path_to_your_file_with_properties";

try {
    fis = new FileInputStream(propFile);
    props.load(fis)
    props.setProperty("key", "value");
} catch (Exception e) {
    //handle exception here
} finally {
    //close FileInputStream
}
0

In Java you can set properties dynamically by using the System class , just doing for example System.setProperty("java.library.path","value_you_want"); you can achieve it.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97