In my opinion, the simplest and quickest way to do this is using the command line.
Steps
- Start the Command Prompt. The easiest way is to Shift-Right Click on an empty spot in your Windows (File) Explorer. Make sure no files are selected, though. The idea is that your Windows Explorer should be in the location of your Java files.
- Navigate
to the folder that holds your class files:
Copy the path from Windows Explorer's address bar (more details about WE here), then type the following into the command prompt window:
cd /d -
minding the space at the end, then paste the path that you copied from Windows Explorer's address bar. Press Enter.
- If
you haven't set your path to include JDK’s binaries (compiler and
utilities, including the one that creates jar files), you need to do so by
adding it to your default path (your folder may differ depending on the
version of the JDK that you installed)
path %path%;C:\Program Files\Java\jdk1.8.0_83\bin - Compile
your class(es):
javac *.java -
Create a manifest file and your jar file (Replace IA with the relevant name to your project):
echo Main-Class: IA > manifest.txt
jar cvfm IA.jar manifest.txt *.class
---- or ----
jar cvfe IA.jar IA *.class - Test your jar:
java -jar IA.jar -
Create a batch file so your end user can double click on it to run your command line application (you may also use Notepad to do this):
copy con run.bat (creates the file)
java -jar IA.jar (Press CONTROL Z and Enter to finish and save the file) - Double click on run.bat to test it.