paradigmatic / Configrity

Simple, immutable and flexible configuration library for scala.
Other
132 stars 19 forks source link

What is the default folder used for load("config.file")? #7

Closed meglio closed 12 years ago

paradigmatic commented 12 years ago

It's simply Java default directory. From javadoc java.io.File:

By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.

Now a free tip: You can directly get that value with Configrity:

 val currentDir = Configuration.systemProperties[String]("user.dir")

The currentDir variable will hold the default directory name.

meglio commented 12 years ago

Thanks, very valuable. I'm new to Java at all, that is why I ask such simple questions. This is good that I can use systemProperties. Can you recommend what is the best way to do for my scenario?

I have my deployment directory not related to the user home. Example:

User home: /home/aoi Deployment: /var/www/aoi/jetty_instance/webapps/root.war

Then I have start_prod.sh like this:


#!/bin/sh

export port=$(expr $(cat base_port) + 0)

echo "Starting the 'production' Jetty process at port $port"

nohup java -Xmx$(cat ram_size) -Drun.mode=production -Djetty.port=$port -jar start.jar etc/jetty.xml >> logs/std.out 2>> logs/err.out &
echo $! > prod.pid
echo "The PID is $!"

So must I add something like -Daoi.distconf="/var/www/aoi/jetty_instance/dist.conf"

... and then something like this?

 val distConfig = Configuration.systemProperties[String]("aoi.distconf")

Thanks!

paradigmatic commented 12 years ago

In that case you have to look in environment:

val distConfig = Configuration.environment[String]("aoi.distconf")

Another approach is to put the config file in the classpath and then access it as shown here: https://github.com/paradigmatic/Configrity/wiki/InputOutput (look for "Loading from classpath")

meglio commented 12 years ago

Thanks, I'll try environment. P.S. I do not know / do not understand what classpath is.

paradigmatic commented 12 years ago

You will need to spend some time learning about Java basics to understand how the JVM works. For the classpath start with:

http://en.wikipedia.org/wiki/Classpath_%28Java%29

meglio commented 12 years ago

Thanks for your quick answers and links! yes, I'm spending 10+ hours a day now to dive into Java/Scala word.

meglio commented 12 years ago

I just discovered that -Dxxx parameter can be retrieved with using:

Configuration.systemProperties[String]("xxx")

(and not Configuration.environment)

paradigmatic commented 12 years ago

Indeed. I'm sorry if you lost some time. I was sure that -D were treated as environement variables. Unfortunately Java has environment and system properties and it's very confusing to know which thing is where. Perhaps, I will provide an unique configuration which merges both.