In this post, we deploy our tic-tac-toe Java GUI app so that it can be invoked either by double-clicking it or through the command line. Note: These steps below were performed on a Windows system.
- First, assemble all the Java source files in a folder of your choice.
- Open your Command Prompt.
- Navigate to your chosen folder in the Command Prompt using the cd command. e.g. cd Java\progs\TicTacToeGUIDemo
- Compile all the Java source files with javac compiler. e.g. javac -d . *.java.
* means all Java files in the current folder.
- After successful compilation, the root package of your app will appear as a folder. In our case it’s ‘com’.
- Now, we need to create a manifest file to help us create a java archive file or JAR file.
This file can be used to launch the app just by double-clicking on it.
It can also be invoked using the java command from Command Prompt. e.g. java -jar TicTacToe.jar
- Open Notepad and create a blank new file called manifest.mf
- In this file, type:Main-Class: com.tictactoe.gameplay.AWTTicTacToe. This is the main class name, qualified by the full package name.
- After step 8, be sure to add a blank new line in the text file manifest.mf
- Save the manifest file and close it.
- Go back to your Command Prompt.
Type the following: jar cvmf manifest.mf –jar file name– –root package folder name–
e.g. jar cvmf manifest.mf TicTacToe.jar com
- You will get some verbose output from the jar command. To open your jar file, you can follow either of the steps in step 6 above.
View the video below to see it all in action.