Compiling and running java application using powershell


I am trying to compile and a sample file.
I have my jdk installed in C:\Program Files\jdk1.7\bin.

And I have my in C:\

I am actually a novice in both powershell and java.
I got some examples from web regarding this but many of them advice to run it like this:

java.exe -classpath $Env:CLASSPATH C:\

But when I give this in powershell I get an error called ‘CLASSPATH’ is not defined even after adding it in env variables.

And when I try to compile the code with the following syntax:

So, I am literally lost in this topic . Any step by step procedure to run java programs using powershell for dummies like me will be greatly appreciated.


Setup environment variables in your system.

set JAVA_HOME to C:\Program Files\jdk1.7

add to PATH variable the string %JAVA_HOME%\bin

open new cmd session.

navigate your java source folder.

use javac to compile your java files.


also if you are experiencing difficulities upon launching an executable via PowerShell check this Microsoft TechNet article


Compiling and running java application using powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply