question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Boot use case: using `spring-boot-loader` and classpath jar order

See original GitHub issue

Thank you @chanseokoh for this thorough and well written explanation ! You’ve made clear, precise and wise points that have changed my mind 😃.

We are using Jib with Spring Boot (and JLink, but that’s another topic) and are very happy with it. Please continue the good work.

As you say at one point it might be useful to have this kind of capability. One case where I think it might be useful is when defining our own entrypoint. When that happens we need to define ourself the java execution command, something like

# Retrieve the files present in the /app/libs directory before subsequently joining them with a ':'
LIBS=/app/libs/*
exec java  ${JAVA_OPTS} -cp /app/resources:/app/classes:${LIBS/ /:} ${MAIN_CLASS}

In that case I think the spring-boot-loader might do a better job than us, since it will handle the classpath and the main class for us.

Also, although I’m not sure if it’s significant, Spring Boot now creates a classpath.idx file providing the ordering that jars should follow when added to the classpath. At one point it might be a good idea to follow what is written in that file.

_Originally posted by @celcius112 in https://github.com/GoogleContainerTools/jib-extensions/pull/31#issuecomment-655584059_

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
chanseokohcommented, Jul 9, 2020
# Retrieve the files present in the /app/libs directory before subsequently joining them with a ':'
LIBS=/app/libs/*
exec java  ${JAVA_OPTS} -cp /app/resources:/app/classes:${LIBS/ /:} ${MAIN_CLASS}

I’m just curious. Why do you expand file paths in /app/libs using a shell? If you pass the literal * (without expanded by a shell), then JVM will expand it internally (will match *.jar files only).

And also we’ve heard a potential risk when listing all the dependencies on the command line, as some OSes may have a relatively short limit on command length (although I think in practice it’s very rare to hit this issue unless you have hundreds of dependencies rooted deep in paths).

0reactions
elefeintcommented, Aug 5, 2022

I’ll keep it here, but with the note that this should be implemented as an extension.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Executable Jar Format - Spring
Spring Boot Loader -compatible jar files should be structured in the following ... and it provides the ordering that jars should be added...
Read more >
Spring-boot inner jar files loading order? (embedded tomcat)
It lists all of the nested jars "in the order that they should be added to the classpath". If you unzip the jar...
Read more >
Spring Boot Classloader and Class Overriding - DZone Java
Learn how to temporarily override library classes with your own custom implementations while keeping Spring Boot's classloader happy.
Read more >
Launching a Spring Boot Application Programmatically - Toptal
Spring Boot loader classes. Spring Boot Classloader will first set JAR libraries in the classpath and then project classes, which makes a slight...
Read more >
Spring Tips #2: Layered JARs with Spring Boot 2.3 - Tratif
So, how creating a Docker image with Spring application can look like? ... dependency JARs; spring-boot-loader – includes loader for JARs ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found