 Hey everybody, it's Brian and we're back with the Java Compiling video. I apologize I had to split this into two videos. I was running out of time. YouTube only allows 10 minutes and this one's going to go over a little bit. Last time I said there were three commands and I only covered two. Remember the first one was Java. That's how you run class files. Second one was Java C, which how you compile them. Today we're going to be discussing the JAR command. What is JAR? JAR stands for Java Archive. Java Archive or a JAR file is simply a zip file. If you don't know what a zip file is, I beg you, go take a basic computing class. But I will explain it here anyways. A zip file is quite simply a file that has other files in it and they're compressed to save space. So a JAR file is just a compressed file with other files in it. One of those files is a manifest file. The manifest file tells Java to execute this program. Now to create a JAR file, you notice how you got these list.options C for create, F for file. What you need to do is you need to be in the same directory as your class files or you can use a class path. Here's main.class and what you do is you just type JAR and give it the options we're going to create. So we do C, remember, create file, specify the archive name. So we'll type F and we'll call it mine.jar and we want to add all the class files. So we'll say start.class and when you do that, it doesn't give you anything back. It just exits. So what happened? When you go in your directory, you see we now have the mine.jar. If we rename this to a zip file and open it up, you see that it has created this and there's our main class. There's our manifest file. Manifest file is going to be blank because, quite frankly, we haven't added anything to it. Excuse me, but I'm just showing you that you can create this by the command line in easier way. Let me actually delete that. Go into Eclipse and let's just make, you know, a couple new class files here in class. We'll call this a I know this isn't really standard naming convention. I'm just doing it for the sake of example B. So we've got a package with a bunch of classes in it. Run it, same functionality. What you can do is go to file, export, runable jar file. Select the launch configuration. I know this looks confusing, but you're just saying the file you want to launch. In this case, main out of the test project. See, here's main test. Export, where do you want to put it? We're going to call this windtest.jar and hit finish. Creates the file there's windtest.jar. Now, why are we doing this? Well, if you want to distribute this, you'd have to give these three files to the end user. If you put it in a jar, everything's nice and neat in this one file. Actually, let's just rename this, open it back up and you see sure enough, there's our class files. There's our manifest file. Now the manifest file, remember we'll tell this how to run this. Inside that manifest file it's saying run the main class. Eclipse does that automatically, so you don't have to mess around with it. Now we've got this.org. What's this? These are Eclipse items. Eclipse adds these automatically. Let's run this, or I'm sorry, turn this back into a jar file and then go to your command line. Now how do you run a jar file? You type Java and we're going to say j-a-r and then give it the name of the jar file. In this case windtest.jar and you see it works. Remember that manifest file is being loaded when Java is given the jar command. It's uncompressing that, looking for the manifest file and saying what do I need to run? The manifest file says run main.class so then it runs that. And that is the basics of how to use a jar file. Now remember you don't need any of these class files. Let's actually just delete them. So you just distribute that jar file. Just for the sake of clarity here you run it and you see how it runs. Even though you deleted the class files it's because everything's contained within this jar file. Now the next tutorial I'm probably going to show you how to convert this into an EXE just for fun. But anyways this is Brian. Thank you for watching and today we learned how to make jar files.