0

I'm not sure if it is best practice but I add MySQL-connector jar to the extensions directory of my Java install directory to I can easily connect to MySQL databases.

I also set environment variables to point to various directories so that I can develop on different machines and only define environment variables locally and code doesn't have to be modified for file paths.

In either case of the above I find that unless I reboot my computer java does not recogise either. What happens during a reboot to Java? Is some config file updates by a java process? Can you update this without having to reboot?

To test this I have created a new environment variable on both Mac (adding to .MacOS/environment.plist), Linux (Ubuntu 12.04) and windows 7 (via control panel). I then used System.getenv("TestVar"); which returns null. Running set from the command line shows it exists though. After a reboot System.getenv("TestVar"); returns the expected value.

2 Answers 2

2

Ultimately your goal is to include jar files in CLASSPATH . its up to you how include jars in classpath but this is not good practice to put jars inside extensions directory . While running your program modify CLASSPATH value .

 java -cp jar1:jar2:jar3:dir1:. HelloWorld
 java -classpathjar1:jar2:jar3:dir1:. HelloWorld
Sign up to request clarification or add additional context in comments.

5 Comments

My question is not really about how to set the classpath but more about how and when does java set what jars it sees on the default classpath and also how does it see environment variables. A reboot updates any changes to either but I'd like to know if it's possible to do this without a reboot.
I never faced this type of problem .If you declare any environment/user variables it must be accessible from java program.The other option is you can set environment variable in command line like java -Dmypath="c:\\test" HellowWorld .
It is accessible but only after a reboot which is what I am finding odd.
On my windows machine I did as the answer in that reference says. I'm not sure if my question is related though. I can see the variable in any new shell but Java can't
2

As far as setting environment variables goes the on Ubuntu a log out is required

https://superuser.com/questions/339617/how-to-reload-etc-environment-without-rebooting

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.