Setting new enviroment variables

 Sometimes if you want to use new commands in Windows command prompt you need to edit your environment variables. With this little article I hope you are then able to use for example Oracles javac command in Windows 7 command propmt.

Setting ups and warnings

For this article I’m trying to tell you how are you able to add new commands via editing your computer environment variables. Note that you really should have a good reason to edit them, so if this is necessary for your life works, then you could do it. Otherwise I advice not to play with your environment settings.

To use Oracles javac command first you need to download Java Development kit from Oracles site.  Then you need to actually write some code with text editor, like notepad++ or with the regular notepad. If you use regular notepad, remember to with all file types, not txt. files. For example if you are trying to write “Hello World!” with Java-language here is an example.

public class HelloWorld {
     public static void main(String[] args) {
     System.out.println("Hello world!!");
    }
}

Note that unlike in Eclipse where you want to also type package name, in this exercise it is not essential but if you would like to use them, then referring it is little different. I think it could be like this: package.HelloWorld.java .

Editing system variables

To edit your system variables go to control panel -> System and Security -> System . Here choose from left side Advanced system Settings.
When pop-up Window opens go to tab Advanced and below press Enviroment Varaibles.
Now a new pop-up window opens and here you are able to add new Variable. There are two ways to create new variable: For the system and all it’s users or only Current user.

  • I recomend using it only for this user, if you use home computer.
    Choose new.. -> and name it Path and then place the varable path.
    Path means the bin folder in Java development kit’s installitation location.
    This could be something like:  C:Progran Files\Java\jdk\bin\
    !!!REMEMBER THAT THE PATH IS IN YOUR COMPUTER!!!

Testing new command

To test your new commands open cdm.exe (Windows command monitor/prompt). Easily to discover if the path was right type: javac -help or javac -version .

If nothing pop-ups in either case, then you might have wrong path value. If it worked then go to the folder where your HelloWorld.java file is located.
Then here type: javac HelloWorld.java . If you didn’t get any errors you can launch your Java code by: java HelloWorld . Then you should get Hello World! text in your command monitor.

Summary

Editing your system environment variables isn’t recommend if you aren’t using these particular commands. But of you really need them, this is one way to do it. For me it worked.

– Tuomas Törmä

Sources

  • Try and err
  • Colleague Santeri Salonen, wordpress

Leave a comment