Utilities like fastjar, gjar, and jar help you manually or
programmatically build JAR files, while other toolchains such as Maven
and Gradle offer features for dependency management.
![Someone wearing a hardhat and carrying code ][1]
One of the many advantages of Java, in my experience, is its ability to deliver applications in a neat and tidy package (called a JAR, or _Java archive_.) JAR files make it easy for users to download and launch an application they want to try, easy to transfer that application from one computer to another (and Java is cross-platform, so sharing liberally can be encouraged), and easy to understand for new programmers to look inside a JAR to find out what makes a Java app run.
There are many ways to create a JAR file, including toolchain solutions such as Maven and Gradle, and one-click build features in your IDE. However, there are also stand-alone commands such as `jarfast`, `gjar`, and just plain old `jar`, which are useful for quick and simple builds, and to demonstrate what a JAR file needs to run.
### Install
On Linux, you may already have the `fastjar`, `gjar`, or`jar` commands as part of an OpenJDK package, or GCJ (GCC-Java.) You can test whether any of these commands are installed by typing the command with no arguments:
```
$ fastjar
Try 'fastjar --help' for more information.
$ gjar
jar: must specify one of -t, -c, -u, -x, or -i
jar: Try 'jar --help' for more information
$ jar
Usage: jar [OPTION...] [ [--release VERSION] [-C dir] files] ...
Try `jar --help' for more information.
```
I have all of them installed, but you only need one. All of these commands are capable of building a JAR.
On a modern Linux system such as Fedora, typing a missing command causes your OS to prompt you to install it for you.
Alternately, you can just [install Java][2] from [AdoptOpenJDK.net][3] for Linux, MacOS, and Windows.
### Build a JAR
First, you need a Java application to build.
To keep things simple, create a basic "hello world" application in a file called hello.java:
```
class Main {
public static void main([String][4][] args) {
[System][5].out.println("Hello Java World");
}}
```
It's a simple application that somewhat trivializes the real-world importance of managing external dependencies. Still, it's enough to get started with the basic concepts you need to create a JAR.
Next, create a manifest file. A manifest file describes the Java environment of the JAR. In this case, the most important information is identifying the main class, so the Java runtime executing the JAR knows where to find the application's entry point.
Or you can use the `jar` command. Notice this one doesn't require a Manifest file because it auto-generates one for you, but for safety I define the main class explicitly:
```
`$ jar --create --file hello.jar --main-class=Main Main.class`
```
Test your application:
```
$ java -jar hello.jar
Hello Java World
```
### Easy packaging
Utilities like `fastjar`, `gjar`, and `jar` help you manually or programmatically build JAR files, while other toolchains such as Maven and Gradle offer features for dependency management. A good IDE may integrate one or more of these features.
Whatever solution you use, Java provides an easy and unified target for distributing your application code.
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/build_structure_tech_program_code_construction.png?itok=nVsiLuag (Someone wearing a hardhat and carrying code )