Java Chapter -17
Hi Everyone In this article we are going to learn about deploying the application. So Let’s get Started.
So everyone have common question that is once we are done with our development, what is it that we deliver to the end user???? The most important things are end-users don’t have a system identical to ours. As well as, they don’t have our application. So now it’s time to get our program in shape for deployment to The Outside World.
So What are the ways that we can deploy the application to the outside world. There are 4 ways, but in this article we are going to learn 1 way and in my next article I'll explain another and I'll keep the rest on your hands.(Because Searching is the beginning of Learning…)
As I mention you can clearly see the Four types of deployment. In this article Let’s take Executable Jar Deployment option and explain it further.
When it comes to Local it means that the entire application runs on the end user’s computer as a stand-alone, deployed as an executable JAR.
Before we are going to the deployment part we need talk about something more important which is separating the code and class files to different directories.
A single directory with a large number of source code and class files is a mess. so we need to make sure the compiled class files didn’t land in the same directory of source code.(Why it’s so important…You’ll understand Why…). . We recommend an organizational scheme that’s become almost standard to organize our class and source files.
Get farook fazni’s stories in your inbox
Join Medium for free to get updates from this writer.
In this scheme we create a project directory, and inside that we have to create a directory called source and a directory called classes. And then we save our source code (.java files) into the source directory. Then we need compile our code in such a way that the output (the .class files) ends up in the classes directory. (So How do we do this….)
As the image says we need to use -d flag which helps us to get decide which directory the compiled code lands in. So now our directly looks like this,
(So now what….) Simple Let’s Put our Java in a JAR.
(You mean JAR JAR….)A JAR file is a Java ARchive. It’s based on the pkzip file format, and it lets us bundle all our classes. which means we can handle a simple JAR to the client instead of many classes(Yes we are giving the classes to the client not the source code…..). (That’s the reason we arranged all class files into a separate directory). But the real question What does a client do with JAR(It’s a JAR……) we have to make a JAR executable file so the end user doesn’t need to extract files out before running the program. They can run the file While the classes are in JAR file(Not extracted….). So How do we do it.
In order to do it we need to create manifest file, which goes inside the JAR and holds information about the files in the JAR(OHhhh Another File…..).
Don’t worry it’s not a big deal the manifest file need to tell the JVM which class has the main method that’s all……
Now we are in the end of the article so at the end all we need to do is run the JAR….And the most important thing that we need to remember that the JVM doesn’t care where your classes come from, as long as it can find them. And one of the places the JVM looks within a JAR files in the classpath. If it can see a JAR, the JVM will look in that JAR when it needs to find and load a class.
That’s all for this article in our next article we’ll learn about another deployment type. I hope you guys got something. Let’s meet in next article soon until then bye bye. OH wait…. Most of the images in this article are taken from the Head First Java book which is written by Kathy Sierra, Bert Bates. Don’t forget to read the book as well.
Reference: Head First Java, 2nd Edition [Book] (oreilly.com)









