[
https://issues.apache.org/jira/browse/CAMEL-17738?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17501859#comment-17501859
]
Brad Harvey commented on CAMEL-17738:
-------------------------------------
Please try
[https://github.com/bradhgbst/camel-spring-boot-examples/tree/CAMEL-17738]
Changes were:
* Change routes-configuration/pom.xml to create the spring boot fat jar with a
different name ("exec" classifier) and leave the original plain jar so it can
be used as a library.
* Add a new example subproject routes-configuration-nested. It nests the
plain jar created by routes-configuration.
* Remove unrelated modules from the parent pom - I was having trouble getting
it all to install.
>From the parent project run "mvn install".
The following things work fine - all routes are loaded and run:
* Running "mvn spring-boot:run" from either of the subprojects
(routes-configuration & routes-configuration-nested)
* java -jar
routes-configuration/target/camel-example-spring-boot-routes-configuration-3.16.0-SNAPSHOT-exec.jar
{code:java}
2022-03-06 12:22:10.925 INFO 14492 --- [ main]
o.a.c.impl.engine.AbstractCamelContext : Routes startup (total:3 started:3)
{code}
But what does not work is:
* java -jar
routes-configuration-nested/target/camel-example-spring-boot-routes-nested-3.16.0-SNAPSHOT.jar
For that one, the java route & error handler are loaded but nothing else.
{code:java}
2022-03-06 12:34:05.286 INFO 12568 --- [ main]
o.a.c.impl.engine.AbstractCamelContext : Routes startup (total:1 started:1)
{code}
Quite tricky to test when it is only when run from the jar that it fails. Hope
that helps!
> camel-spring-boot - Cannot load resources from nested jar inside spring boot
> fat jar
> ------------------------------------------------------------------------------------
>
> Key: CAMEL-17738
> URL: https://issues.apache.org/jira/browse/CAMEL-17738
> Project: Camel
> Issue Type: Bug
> Components: camel-spring-boot
> Affects Versions: 3.14.1
> Reporter: Brad Harvey
> Priority: Minor
> Fix For: 3.14.3, 3.16.0
>
>
> In camel 3.14.1 / spring boot 2.6.3 XML routes cannot be loaded from a nested
> jar. I suspect earlier versions of both are also affected, but Camel 3.4.x +
> Spring Boot 2.3.x did load them ok.
> In this code from FatJarPackageScanResourceResolver, "name" is the nested jar
> name - it will end in .jar. To traverse into the spring boot jar it would
> need to go into the second branch - the "else if" - but it will always go
> into the first branch because it is a not a directory and the name does not
> end in .class.
>
> {code:java}
> String name = entry.getName();
> name = name.trim();
> if (!entry.isDirectory() && !name.endsWith(".class")) {
> name = cleanupSpringBootClassName(name);
> // name is FQN so it must start with package name
> if (name.startsWith(packageName)) {
> entries.add(name);
> }
> } else if (inspectNestedJars && !entry.isDirectory() &&
> isSpringBootNestedJar(name)) {
> String nestedUrl = urlPath + "!/" + name;
> log.trace("Inspecting nested jar: {}", nestedUrl);
> List<String> nestedEntries =
> doLoadImplementationsInJar(packageName, jarStream, nestedUrl, false, false);
> entries.addAll(nestedEntries);
> }
> {code}
>
> I think this code was copied from the class resolver and
> name.endsWith(".class") changed to !name.endswith(".class") but it doesn't do
> what is needed.
>
> Solution may be to swap the order of the if checks so that nested jars are
> found & traversed first.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)