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

  1. In the <plugins> section of the pom file, add the following for the Maven Shade Plugin…
  2. In a Terminal window, change directory (cd) in to the root of your project
  3. Enter the following command to package the JAR file (whilst skipping any test run)…
    mvn 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.



Liked it? Take a second to support Thomas on Patreon!

Previous Article

Next Article

One Reply to “Part 8. Packaging into a JAR (Maven JAR Plugin)”

  1. Hi Tom,
    After setting up the paralel Cucumber for Maven now I cannot build the project as it those target BaseTestRunners are using cucumber.api.CucumberOptions;/cucumber.api.testng.AbstractTestNGCucumberTests; instead of the io.cucumber* variants as I have setup in my repo following your tutorial.

    Can you please advise ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.