How to Create Jar File

preview_player
Показать описание
Follow this step by step guide to learn how to create a jar file and see how java archive files can be created with the help of the command prompt.

Jar stands for Java Archive which is a file format used to aggregate java classes and other resources such as images or text into one package.

We can create a jar file in several ways. For the purpose of this tutorial, we will be creating a jar file with the help of the command prompt.

Step 1 -- Open the command prompt

First of all, open the run command by pressing the "windows + r" key. Over there, type in cmd and hit the enter key in order to open the command prompt.

Step 2 -- Change the Directory

In the command prompt, go to the directory where the java classes are kept. In order to do so, type the "cd" command followed by the desired directory name.

For the purpose of this tutorial, we will go to the directory named as "java classes".

In order to check the files in this folder, enter the "dir" command. You will notice some java files present with ". java" extension in this directory. These are the files of which we are going to make a jar file.

Step 3 -- Enter the jar --cf command

Simply type the "jar - cf myfile .jar *. java" command and then hit the enter key.

After done with that, simply open the directory listing again by dir command to see whether the file has been created or not. And you will notice that a file with .jar extension will appear with the same name we used in the command.

Step 4 -- View the jar file

Let us open up the directory through windows explorer, right click on the jar file and open its properties.

It can be seen that this type of the file is an Executable Jar file. And this was all about creating a jar file.
Рекомендации по теме
Комментарии
Автор

❗ Subscribe To Our Main YouTube Channel

howtechweb
Автор

Alright, everyone who is struggling with 'jar' not being recognized as an internal or external command I got your back. You have to set a PATH to your JDK bin file. Now if you dont know what that means it's fine just follow these steps:
So first find your Java file and go to the bin, mine is under C:\Program Files\Java\jdk-12.0.2\bin. Copy that directory!! (you'll need it later) To copy it just click on the directory at the top and it'll highlight itself, then either right click or ctrl+C.
Now, go to files, right click -ThisPC, click on properties, go to Advanced system settings, then under the Advanced tab, click Environment Variables at the bottom, then on the bottom scroll window 'System Variables' click on 'Path'. Create click New and paste that directory link. Now click OK and it should work.


Hope this helps, I've been confused for the last couple hours trying to figure this stuff out.

brandonbudai
Автор

'jar' is not recognized as an internal or external command,
operable program or batch file.

programmerinnovation
Автор

If jar is not recognized, you must edit your environment variables so that your computer knows where to find jar, an important point which this video glosses over, but this video glosses over A LOT.

chimpspecialist
Автор

Although, when I run the .Jar is no error message, but that program also does not open. Can you help me?

dako
Автор

Nice. Quick, clear and direct tutorial. Great job.

raynersulyak
Автор

whenever i type in jar in the cmd it says unrecognized command...

reachcarter
Автор

when i typed in cd java classes it didnt work

jamalalfred
Автор

can someone help me turn a folder of files into a jar file

rambunctiousdelinquent
Автор

Same problem as the others. "Unrecognized command" even though I installed the JDK and set a path to it... at least take your time to answer comments too!
 

RollingBarrel
Автор

What do you mean by 'command'? Sorry for being an idiot, but I just have no brain.

Angry