FWIW, Giulius - https://github.com/timboudreau/giulius - also deals with 
binding command line arguments to @Named variables (and providing default 
values if no value is on the command line) - when setting up your Settings, 
do 

        Settings settings = SettingsBuilder
                .forNamespace("my-server")
                .addDefaultLocations()
                .parseCommandLineArguments(args).build();

        Dependencies deps = Dependencies.builder().add(settings, 
Namespace.DEFAULT)
                 .add(yourModule).build(); // wraps the injector, or you 
can get it directly

        Foo foo = deps.getInstance(Foo.class);

and if your code looks for @Named("port") String foo, then if your app was 
started with, say,

java -jar myJar.jar --port 8080

you will get the value from the command line;  if not, it will look in 
/etc/my-server.properties,
~/my-server.properties and ./my-server.properties and lastly on the 
classpath (in META-INF/settings/my-server.properties)
for a value for it;  you can use e.g. @Defaults("port=8000") to provide a 
default value.

That way you get a unified way of setting up configurable settings, without 
needing to have special
command-line handling code beyond calling 
SettingsBuilder.parseCommandLineArguments(args).

-Tim

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to