Putting a fat jar into a Docker container is a waste of storage, bandwidth and time. For instance, we could reduce the effective size of new artifacts from 75 MB to only one MB! And the best is that there is a plugin for Maven and Gradle handling everything for us. The layer mechanism of Docker is powerful. If all of your applications are using the same base image like openjdk So we save storage in the Docker registry and speed up the upload to and download from the registry because fewer MBs have to be transferred Docker only transfers the layers that are new to the registry.

This fat jar is 72 MB big and is added in the last line of the Dockerfile. This means that each new release will take 72 MB storage and 72 MB have to be uploaded to and downloaded from the registry. Content of a fat jar. So the code that is usually changed for a new release is only a few MB.

Still, we copy all the dependencies and resources again and again in each artifact. Moreover, the space wasting is getting even worse when you are creating a unique, deployable artifact for each commit using the git commit hash as the version number of the artifact. That makes sense for continuous delivery but leads to a high storage consumption as every commit occupies additional 72 MB.

What are useful tools for analyzing docker images and visualizing the impact of fat jars in docker images? The interactive command-line tool dive shows the fat jar layer. We extend this approach by introducing different layers for the dependencies, the resources, and the code. And we order the layers by the frequency of change. Splitting up the application with three different Docker layers for the dependencies, resources, and code. A usually release will now only take 2 MB instead of 72 MB.

Now, if we create a release that only consists of code changes, we only require 2 MB of storage because the layers for the resources and dependencies can be reused. Jib is available as a plugin for Maven and Gradle and it simplifies the containerization of Java applications.

A nice pitch for Jib can be found in the Google Blogbut one characteristic is most important for us: Jib scans our Java project and creates different layers for the dependencies, resources and the code.

The three different layers for the dependencies, resources, and code in our built docker image with Jib. Clean-up 1 Disable the maven-deploy-pluginthe maven-install-pluginand the maven-jar-plugin. These steps are not required anymore and should not be executed even if the developer types mvn deploy out of habit.

Clean-up 2 Remove the spring-boot-maven-plugin if you are using Spring Boot. There is no need to create a fat jar anymore. Jib allows configuring the JVM flags and program arguments in the pom. Instead, the configuration depends on the deployment environment local, QA, production. But those dependencies are copied again and again into each fat jar leading to a waste of space, bandwidth and time. Usually, the code is the only part that has been changed.

Jib provides an easy-to-use plugin for Maven and Gradle to implement this approach. No need to write a Dockerfile manually. A fat jar contains three parts: The dependencies: The used libraries are taking most of the size but they change rarely.

Most of the time when we create a release, we only touched our code and not the dependencies. Still, the dependencies are copied into each release. But they are also duplicated in each release. The code: The code has only a small share of the total size of the fat jar KB - 2 MB but is the most frequently changed part of it. What are the steps?This article shows an example of how to deploy a Spring Boot fat jar on a remote server using Bamboo.

As reminder, a fat jar is a self-contained jar, in other words it contains all the dependent libraries. A deployment project has to be associated with a Bamboo plan. Usually, it produces an artifact and this is what you want to deploy. Is it without saying that in our case the artifact will be a fat jar. If you do not know how to create a deployment project click on this link. The deployment can be triggered right after the plan succeed or it can be scheduled at a specific time.

And then we will focus on the Edit tasks. Here are the tasks needed:. Normally in the dropdown list appears the name of the artifact from the Bamboo plan, just select it and save. If the artifact is not listed, go back to the plan configuration and make sure the shared option is checked in the artifact tab. From now, I will use only Script tasks to manage the deployment.

The first script task is used to upload the jar on the remote machine. There might be already an instance of your application running on the server.

You should stop it before starting a new one. I could have done something much smarter. But in my case I know this is the only app which runs on this port. Bamboo plan A deployment project has to be associated with a Bamboo plan. Define the artifact You have to tell Bamboo where to find the artifact. Deployment project You must first create an environment, like this one: And then we will focus on the Edit tasks. Clean working directory task This is one of the default task.

Just keep it as it is. Scripts From now, I will use only Script tasks to manage the deployment. In the future there might be more than one app running so this one will be the primary one. Upload jar The first script task is used to upload the jar on the remote machine. The name of the jar is the one generated during your build process in the target folder. In a normal maven project the name should be artifactId-version.

Check if there are processes running with the app. Process not found.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here.

Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I was expecting that any dependencies I specify with the implementation dependency configuration would be placed in the Spring Boot fat jar when I execute the assemble task. However they are not. I've resorted to using the deprecated compile dependency configuration for now, but I'm confused as to why implementation doesn't work.

In the example above, I would have expected commons-lang It does not! The most likely explanation is that this version of the Spring boot plugin did not support the reworked configurations of the Gradle java plugins. Learn more. Asked yesterday. Active today. Viewed 21 times. I'm working on some legacy code with the following versions: Gradle 4. Simplified build. Richard Lund Richard Lund 1. New contributor. Active Oldest Votes.

spring boot fat jar

Louis Jacomet Louis Jacomet 9, 2 2 gold badges 19 19 silver badges 26 26 bronze badges. Richard Lund is a new contributor. Be nice, and check out our Code of Conduct.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Featured on Meta.

Feedback on Q2 Community Roadmap. Technical site integration observational experiment live on Stack Overflow. Question Close Updates: Phase 1.

Dark Mode Beta - help us root out low-contrast and un-converted bits. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.In most of the minds, microservices is an approach to make a traditional monolithic system more structured, dividing it into logical components that correspond to different functional areas of application. Thus, acting as a microservice, each component becomes self-contained, easily scaled, maintained and even upgraded without affecting the overall system.

Also, with microservice architecture, you can use a software written in different programming languages, including Java. Such freedom attracts but may frighten at the same time. You can spend hours reading numerous articles in the net, regarding how to build microservices along with some boring examples. However theory without practice gets nowhere. For a quick start, we have prepared a package with Maven and popular framework Spring Boot inside Java Engine node.

It automates building a sample Java project as Fat or so-called Uber Jar to run it as a microservice. Or you can Import the required manifest using the link from GitHub:.

spring boot fat jar

If required, change installation settings such as environment name or Git repository link to a custom Spring Boot project. Then press Install. When the installation and building of the project are completed, a corresponding message appears. You still need to wait a few minutes for deploy to be finished feel free to track the process in Tasks panel.

Afterwards, you can make sure, that application is up and running by pressing Open in browser button. You can use just created Maven node for building extra projects and deploying them to different environments to get a set of distributed microservices.

First of all, create a separate environment with Java Engine. Then click Add Project next to the Maven node in the initial environment. Specify the name and link to the project, as well as choose the environment where it should be deployed. Additionally, you can activate automatic updates. More details on how to build and deploy Java applications can be found at the Maven node documentation.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I'm using spring-boot-maven-plugin to package my REST service. I'm building the jar using mvn clean install or mvn clean package.

After I decompile the jar, I don't find any of the dependencies added I was expecting it to be a fat jar with all dependencies. When I run the spring boot using java -jar myapp.

spring boot fat jar

It's clear that artifact didn't build as expected. However, if I start spring boot application using maven. How can I fix the build issue so that I can start app using java -jar command. Or probably it's plugin configuration issue.

Just checked: it works with spring-boot-maven-plugin Learn more. Asked 2 years ago. Active 2 months ago. Viewed 7k times. EDIT: It's multi-module maven project. Pankaj Pankaj 2, 10 10 gold badges 37 37 silver badges 74 74 bronze badges. Judging by the screenshot, there are a number of problems with the repackaged jar. Active Oldest Votes. JGleason 6 6 silver badges 22 22 bronze badges.

I used "mvn clean package spring-boot:repackage". Found the reason why it wasn't working. My project is multi module maven project. Need to use classifier as per this documentation. It works with 1. Hi, please give a short description on why or how this code will solve the OPs question. The answer does not explain what and how the original issue will get solved. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.

Fat/Uber Jar - Create One Jar file with all dependent libraries required for the Gradle project

Post as a guest Name.By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I tried creating said jar, at first the result was 86k and did not launch, because it was missing some Spring boot classes.

spring boot fat jar

I concluded this jar I made contained none of the application's dependencies, and since I did want a completely self-contained jar, I should do more research. I hope. I'm familiar with the idea of the ternary operator and I can see what it's trying to do here.

Unfortunately it is still not working! Here is the error I get on launch, and below is my build. I want a spring boot application with embedded tomcat fully contained in a jar. Am I doing something highly unconventional? Any help at this point would be greatly appreciated.

You don't need to make yourself additional gradle configurations for building a fat-jar artifact of spring-boot application, since you use a gradle spring boot plugin. It already has a task bootRepackage to do it for you. You can read about it in official user guide here and here. Just delete all you've done to unzip dependencies content and use this task to get a single jar file with your application.

By the way, you may be interested to look at some other solution, which possibly could provide a better archive sizes, you can read about one of them, called Capsule, in this article. See this plugin's homepage to find the latest version. To to build the jar, I used the bootJar task to compile the jar. My project doesn't have the bootRepackage task and using a. Maybe that's something I should try to configure using something like dependsOnbut for now this works for me.

I have a multimodule project, so maybe configuration is different for single module projects. I'm also using com. Learn more. Asked 4 years, 5 months ago. Active 4 days ago. Viewed 18k times. About 80 lines of successful Spring Boot launch messages followed immediately by: AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt org.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account.

Also see and If there's any influence we can put on the Jersey project to merge that PR, I think that would help. It looks like there are also issues with packaged WAR files and trying to find any classes in, not just those inside a jar file:. There's an updated pull request but it's yet to be merged by the Jersey team.

In the meantime you can use the workaround described here.

Automatic fat jar deployment with Bamboo

Judging by the branches in the repository, it doesn't look like the Jersey team are maintaining 2. If you believe the existing PR is defective, a new PR against master currently building 2.

The Jersey team are best placed to then decide if and how it should be backported to earlier versions. I make a pull request into 2. Jersey maintainers aren't interested to solve this issue. I found out that there is a problem with the way Jersey does ClassPath Scanning. It works well with "Standard" Jars. Otherwise, it won't work.

I'll keep investigating the alternatives. I had the same issue, for me it worked by changing spring-boot dependency from 1. Hopefully they fix it in a future release version. Because Spring Boot 1. The class which extends the ResourceConfig class must contain Component annotation, At run time when spring will create the object of that class, it will load the default constructor of that class and then jersey will register all the provided class.

But here is a catch, all the class must have Component annotation, else Spring will not able to create the object of that related class and at the end, the jersey will not able to register that class. NOTE: To register the class in Jersey, use the register method, packages method is not working in this workaround.

Subscribe to RSS

I found this issue today when I integrated Sprint Boot and Jersey project as well, thanks for mihu86 's solution, and the problem has been fixed now. In addition, I would ask Spring Boot owner, when this issue can be fixed through below solution? If this issue has been fixed ,please help tell me the issue number or version no. I appreciate with your all support. There are is an issue and a PR mentioned above. For ease of reference, they are:. Skip to content.

Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up.


Comments

  1. Link

Add a Comment

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