Issue
This seems like a simple thing that should have been done before, but I can't find anything. I have a Spring app (built with Maven, though I'd also like to know how to do this with Gradle) that gets run in a simple docker container:
FROM openjdk:11
COPY target/*-spring-boot.jar app.jar
CMD java -jar /app.jar
What do I need to do to enable load-time weaving with this setup?
Solution
I added spring-instrument to the pom
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
</dependency>
Added @EnableLoadTimeWeaving
to the application class, changed my build script to unpack the jar
mkdir target/dependency
(cd target/dependency; jar -xf ../*-spring-boot.jar)
docker build -t myorg/myapp .
and updated the Dockerfile as per https://spring.io/guides/topicals/spring-boot-docker/
FROM openjdk:11
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
CMD java -cp app:app/lib/* -javaagent:"$(echo /app/lib/spring-instrument-*.jar)" com.myorg.MyApp
Answered By - Buddy Gorven
Answer Checked By - Marilyn (JavaFixing Volunteer)