Development - Set environment script

on Tuesday, 15 May 2012
To run many of the tools you find in Java development you first have to ensure the environment you're working in is configured correctly - this is often the command line for Windows or shell for Linux. For example when you want to run the 'javac' program from the command line, your computer needs to knows the path to that executable file.

**NOTE** it is possible to make environment variables permanent on a machine so that they only ever need to be set once. This can be dangerous for several reasons:

a) If you set a faulty path you could crash your machine and the change may be irreversible.
b) If you switch machine you will have to try and remember all the changes you made.

Here enters the setenv script!!


This is a very simple script to set up the Windows command line interface to use Java. Copy this into your favourite text editor and save it as setenv.bat. Now, edit the script to include your Java install then open a command line prompt. Once open type "set" and run. A series of value/variables pairs should be displayed but JAVA_HOME should not be set.

Now, run "setenv.bat" and "set". You should now notice both the PATH and JAVA_HOME variables have been set.

And here is the Linux version:

These scripts I have provided are very simple and only currently set up your Java environment. You can use the same principles to set up your build tools or any other third party tools you may wish to run from the command line.

0 comments:

Post a Comment