Running JAR Files with Command-Line ArgumentsĪny Java application can have any number of command-line arguments. The output of this command is shown below. We need to specify the JAR file name and the main class name in the command. Instead of using the -jar option, we will use the -cp option to run a non-executable JAR file. The output of the command is shown below. We can use the following java command with the -jar option to run the executable JAR file. jar -cf HelloWorld.jar HelloWorld.class Running JAR Files Running the Executable JAR File We don't need to pass the name of the manifest file to our command. To create a non-executable JAR file, we will exclude the -m flag. class file shown in the image below was created after running the javac command. And the -m flag will include the content of the manifest file.Īfter executing the above command, a new JAR file with the name HelloWorld.jar is created in our current directory. The -f flag is used to specify the file name.
#Run java jar file archive
The -c flag is used to create an archive file. jar -cfm HelloWorld.jar ManifestFile.txt HelloWorld.class Next, we can create a JAR file by running the following jar command. The content of the manifest file is shown below. To create an executable JAR file, we also need a manifest file. javac HelloWorld.java Creating an Executable JAR File We first need to run the javac command to create the. java file and the manifest file which will be required for executable JAR. This manifest file contains the name of the class that should be executed when the JAR is run.įor this tutorial, we will work with just a single class whose main method prints Hello World. The difference between the two is that an executable JAR file contains a manifest file, while the non-executable JAR file does not contain this. We can create an executable or a non-executable JAR. Creating JAR FilesĪ JAR file is composed of the compiled Java.
#Run java jar file how to
In this short tutorial, we will learn how to create and run a JAR file in Java. JAR files are a great way to share and distribute our Java code with others. class files and other metadata and resources needed for the project. JAR files contain compressed Java project files. bat file and check if Jar file won’t open.JAR is short for Java Archive. bat as an extension in the File Name box. Select the Save as type to All files, and then type the desired name for the Jar file and add. Replace the filename.jar with the actual name of the Jar file. Open the Notepad, and then enter the java -jar filename.jar line in it and click on File > Save as. To do so, right-click the empty space in the folder and select New > Text Document. Jar file and create a new Notepad file in the same folder. bat file and using it each time you want to open a specific Jar file. Jar file not opening can be fixed by creating a. Now, you can reopen the program and see if the Jar file won’t open. Select the Java application and click on the Open button to set it as the default app fro. In the File Explorer, navigate to the Java.exe file via the Programs Files\Jave\Jave version\Bin path. Scroll down to the bottom and click on Look for another app on this PC link. You will see a list of suggested applications and click on More apps at the bottom.
#Run java jar file windows 10
Some people have proven that this solution can fix the Jar file not opening Windows 10 issue. In addition, you can manually select Java as a default app to open the.