Загрузка...

How to CREATE an EXECUTABLE JAR With Dependencies Using Maven

In this tutorial, we'll explore the process of creating a self-running Uber JAR using the Maven Shade Plugin. We start by setting up a Maven project using the quickstart archetype, resulting in a basic project structure with a pom.xml file and a HelloWorld main class. If you need detailed explanations of the parameters, you can find a linked video for reference.

After generating the project, we open it in VS Code and make essential configurations in the pom.xml file, ensuring that the Maven compiler is set to Java 17.

Next, we dive into the main application, which initially prints a "Hello World" message. We enhance it by adding a third-party dependency for working with JSON Web Tokens (JWTs). These tokens, often called "jots," are used for secure information exchange.

We then update our code to parse command line arguments, validate them, and create a JWT with specific claims. We set an expiration time for the token and print it to the console.

Moving on, we encounter an issue where our JAR doesn't include the necessary dependency. To resolve this, we introduce the Maven Shade Plugin to our pom.xml file, configure it to create an Uber JAR, and rebuild the project.

With our larger JAR, which now includes dependencies, we test the application to ensure it functions correctly.

Lastly, we make the JAR self-running by updating the pom.xml file to specify the Main-Class attribute using the Maven Shade Plugin. This allows the JAR to execute without specifying the main class explicitly.

Project Code: https://github.com/BeginSecure/JWTCreate.git

== TimeStamps ==
00:00 Generate a Maven Project
01:39 Create a JWT in Java
05:47 Add Shade Plugin to Maven

#maven #vscode #java

Видео How to CREATE an EXECUTABLE JAR With Dependencies Using Maven канала Begin Secure
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять