1

I am using Guice without any spring dependencies.

Is there way to get System properties passed to java (java -Dfoo="asda") in Module. The goal is to load properties from outside of jar file.

Most examples so far use preexisting properties file

Similar to this question: Guice properties injection

2 Answers2

2

Use Names.bindProperties()

Usage is very easy:

@Override protected void configure() {
  Names.bindProperties(binder(), System.getProperties());
}

Then each time you inject @Named("java.user.home") String you'll get the value of System.getProperty("java.user.home").

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
0

used System.getProperty() as temprary solution. But hope there is more elegant way