How to compile a java project with a terminal/cmd
I got tired of using Eclipse because it was too "plain" and "old style". So I moved on to a program called Sublime Text 3 and I used a package named "material theme" which made the program look flat and all nice and stuff.
But I wanted to code Java in that but I don't know how to compile stuff without using an IDE and it was not easy to find out but I found out that you could do it through the terminal/cmd of your operating system.
But what I don't understand is how I could actually use the javac
command which means Java Compile and I searched and I didn't find out because I couldn't understand anything that was posted on either YouTube or Stack Overflow because I'm new to this whole terminal/cmd Java Compiling thing.
You're almost there buddy!
Just be sure you have the Java Development Kit (JDK)
installed in your system. The JDK provides you the command javac
-which you need to compile your .java
program files.
The javac
command is not that friendly as you think it is. You have to let it know where to find the java file you want to compile.
For example you saved Main.java
inside C:\Projects\Java
you must compile it this way javac C:\Projects\Java\Main.java
.
Then you can run your program this way too java C:\Projects\Java\Main
As mentioned here... You can find a more detailed explanation to the official tutorial.
You need to install java JDK which you can find here
Then you need to right-click on my computer->properties->advanced system settings->Environment variables -> Click on path -> New
Then add the path to the bin folder inside the install folder for JDK.
Then in cmd you can compile with
javac *.java
inside the directory of your code