[MUSIC]
>> Greetings, everyone. Welcome back to
Microsoft's Java for Beginners Series.
My name is Brian Benz, I'm the Cloud advocate at Microsoft,
and I am joined again by Kirk Pepperdine,
who is going to tell us a little bit
more about classes and packages.
This is Part 2 of a three part topic.
Kirk, do you want to tell us a little bit
about yourself and what you want to talk about?
>> Hi, Brian. Thanks for having me here.
I am a Principal Engineer in the Java Engineering Group and we are
responsible for building and contributing to OpenJDK.
In this segment, we'll explore
Java archives and these are otherwise known as JAR files.
There's other ways that we can actually get things to load,
and that is to build what's known as a Java archive or a JAR file.
Now there's a couple of different ways we can do this.
I'm just going to start with a simple version first,
and then we'll move on to a slightly more complicated version.
First, I'm going to go into the where the classes directory is,
and so we need the classes,
so what I'm going to do is I'm going to jar up
the the classes here.
I'm going to make a person.jar
file from everything in the com directory.
Now I'm going to now move the person.jar
file up the directory so it's just right here in front of us.
Now when I run Java,
I'm going to put the jar file on the class path.
Let's start with that and I'm going to use
the abbreviation this time for class path minus CP.
We're going to put in person.jar and we still have to
give our entry point class,
the class that contains our main.
I'm going to execute that.
There you can see that everything works as expected.
In the more complicated version,
what I'm going to do is create an executable jar.
The first thing that we have to do
is we have to create a manifest file.
I'm going to start by creating that in
the src directory, we'll put into a person.mf file.
The first thing that we need to put in here
is a Manifest-Version,
it's going to be 1.0.
After that, we need to specify the Main class.
In here, we have com.model.person,
that completes that task.
We can get rid of our person.jar here.
I can go into classes just to make this a little simpler.
Now what I'm going to do is I'm going to do a jar,
and I'm going to say cfm.
In this case, I'm going to create a jar and be person.jar.
Our manifest file is
going to be src/person.mf.
What we're looking for is everything in
the class path just as we did before.
There we go.
I'm going to copy our jar file.
Up directory, we'll go back up the directory and would go to like
Java minus jar in this case.
I'm going to put in just the name of the jar.
The class loader will read the
manifest and it will sort out what the main class is,
and it will load that class and it will
execute it and we get the results,
as we would expect.
>> Thanks, Kirk. That was great.
That was Part 2 of classes and packages.
Stay tuned for Part 3 and make sure to check out
the rest of the topics for the Java for Beginners series.
[MUSIC]