Packaging into a JAR
A JAR is a package file format typically used to aggregate many Java class files and associated metadata and resources into one file for distribution. It is used to store classes of java created by the user in order to help the runnable and inference concepts embedded within the language.
An uber-JAR—also known as a fat JAR or JAR with dependencies—is a JAR file that contains not only a Java program, but embeds its dependencies as well. This means that the JAR functions as an “all-in-one” distribution of the software, without needing any other Java code.
In this section, we will be creating a fat JAR (one that contains all test classes too, as our project sits within ‘test’), which we can then easily use and distribute (e.g. on build servers).
To do this, we will be using the handy Maven JAR Plugin.
Let’s begin 😀
Adding the plugin to our pom.xml file
- In the <plugins> section of the pom file, add the following for the Maven Shade Plugin…
- In a Terminal window, change directory (cd) in to the root of your project
- Enter the following command to package the JAR file (whilst skipping any test run)…
1mvn package -DskipTests
If you now look in the ./target directory, you should see that two JAR files have been created, one for main and one for test (ending in ‘-test.jar’) 😀
In the next section, we will move towards scaling up our parallel test execution with a Selenium Grid inside docker containers.