Skip to content

ch007m/quarkus-classloading

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Merging classloader

Introduction

This project demonstrates how to dynamically extend a Quarkus-based CLI application at runtime by loading external JARs through a custom classloader. The core idea is to merge an additional classloader — responsible for resolving resources from external Maven artifacts — with the Quarkus application classloader, enabling the application to discover and use classes and resources that were not part of its original build.

The project is structured around two main use cases:

  • Greeting command: loads the dev.snowdrop:model artifact at runtime, instantiates a Message class from it, and renders a localized greeting using messages_xx.properties resource bundles bundled inside the external JAR.
  • Rewrite command: loads the dev.snowdrop:rewrite artifacts including classpath.tsv.gz files, then dynamically invokes a launcher class (OpenRewriteLauncher) to apply OpenRewrite recipes against a target project directory.

This approach is useful when the set of capabilities or domain models needs to be resolved and injected at runtime without recompiling or repackaging the CLI itself.

Greeting command

export JAR_MODEL=$HOME/.m2/repository/dev/snowdrop/model/1.0.0-SNAPSHOT/model-1.0.0-SNAPSHOT.jar 
set JAR_MODEL $HOME/.m2/repository/dev/snowdrop/model/1.0.0-SNAPSHOT/model-1.0.0-SNAPSHOT.jar

java -jar ./cli/target/cli-1.0.0-SNAPSHOT-runner.jar \
  --jar-path=$JAR_MODEL \
  -l en \
  quarkus

To debug

set JAR_MODEL $HOME/.m2/repository/dev/snowdrop/model/1.0.0-SNAPSHOT/model-1.0.0-SNAPSHOT.jar
mvn compile -pl cli quarkus:dev \
  -Dquarkus.args="--jar-path=$JAR_MODEL -l fr quarkus" -Dsuspend

RewriteCommand

export JAR_REWRITE=$HOME/.m2/repository/dev/snowdrop/rewrite/1.0.0-SNAPSHOT/rewrite-1.0.0-SNAPSHOT-jar-with-dependencies.jar
set JAR_REWRITE $HOME/.m2/repository/dev/snowdrop/rewrite/1.0.0-SNAPSHOT/rewrite-1.0.0-SNAPSHOT-jar-with-dependencies.jar

java -jar ./cli/target/cli-1.0.0-SNAPSHOT-runner.jar \
  --jar $JAR_REWRITE \
  --launcher-class dev.snowdrop.launcher.OpenRewriteLauncher \
  --project-dir test-project/spring-boot-app

To debug

export JAR_REWRITE=$HOME/.m2/repository/dev/snowdrop/rewrite/1.0.0-SNAPSHOT/rewrite-1.0.0-SNAPSHOT-jar-with-dependencies.jar
set JAR_REWRITE $HOME/.m2/repository/dev/snowdrop/rewrite/1.0.0-SNAPSHOT/rewrite-1.0.0-SNAPSHOT-jar-with-dependencies.jar

mvn compile -pl cli quarkus:dev \
  -Dquarkus.args="--jar $JAR_REWRITE --jar $JAR_MODEL --launcher-class dev.snowdrop.launcher.OpenRewriteLauncher --project-dir test-project/spring-boot-app" \
  -Dsuspend

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages