This is an automated email from the ASF dual-hosted git repository.

Croway pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new ce389e6a10bd CAMEL-XXXXX: Fix camel-joor MultiCompile classpath for 
Spring Boot fat-jar nested JARs
ce389e6a10bd is described below

commit ce389e6a10bd3556bbca375c37958775281a05b3
Author: Salvatore Mongiardo <[email protected]>
AuthorDate: Wed Apr 29 13:47:45 2026 +0200

    CAMEL-XXXXX: Fix camel-joor MultiCompile classpath for Spring Boot fat-jar 
nested JARs
    
    When running inside a Spring Boot fat-jar (repackaged with nested 
BOOT-INF/lib/),
    the URLClassLoader returns jar:nested: URLs that were silently dropped by 
the
    existing "file" protocol check. This caused runtime compilation failures for
    auto-configure scripts (e.g. spring.datasource.url.java) because required 
classes
    like org.apache.camel.main.MainHelper were missing from the compiler 
classpath.
    
    Fix: extract non-file URLs (including jar:nested:) to temporary files and 
add them
    to the compiler classpath. Temp files are cleaned up in a finally block.
    
    Backport of https://github.com/apache/camel/pull/22811
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../apache/camel/language/joor/MultiCompile.java   | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git 
a/components/camel-joor/src/main/java/org/apache/camel/language/joor/MultiCompile.java
 
b/components/camel-joor/src/main/java/org/apache/camel/language/joor/MultiCompile.java
index 9ef05add4841..66905b1543d1 100644
--- 
a/components/camel-joor/src/main/java/org/apache/camel/language/joor/MultiCompile.java
+++ 
b/components/camel-joor/src/main/java/org/apache/camel/language/joor/MultiCompile.java
@@ -18,6 +18,8 @@ package org.apache.camel.language.joor;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.StringWriter;
 import java.lang.invoke.MethodHandles;
@@ -26,6 +28,9 @@ import java.net.URI;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -107,6 +112,7 @@ public final class MultiCompile {
         }
 
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+        List<Path> tempFiles = new ArrayList<>();
 
         try {
             if (!options.contains("-classpath")) {
@@ -130,6 +136,14 @@ public final class MultiCompile {
 
                         if ("file".equals(url.getProtocol())) {
                             classpath.append(new File(url.toURI()));
+                        } else {
+                            // handle non-file URLs (e.g. jar:nested: from 
Spring Boot fat-jars)
+                            // by extracting the resource to a temp file
+                            Path tempJar = extractUrlToTempFile(url);
+                            if (tempJar != null) {
+                                tempFiles.add(tempJar);
+                                classpath.append(tempJar.toFile());
+                            }
                         }
                     }
                 }
@@ -223,6 +237,25 @@ public final class MultiCompile {
             throw e;
         } catch (Exception e) {
             throw new ReflectException("Error while compiling unit " + unit, 
e);
+        } finally {
+            for (Path temp : tempFiles) {
+                try {
+                    Files.deleteIfExists(temp);
+                } catch (IOException e) {
+                    LOG.debug("Failed to delete temp file: {}", temp, e);
+                }
+            }
+        }
+    }
+
+    private static Path extractUrlToTempFile(URL url) {
+        try (InputStream is = url.openStream()) {
+            Path temp = Files.createTempFile("camel-joor-cp-", ".jar");
+            Files.copy(is, temp, StandardCopyOption.REPLACE_EXISTING);
+            return temp;
+        } catch (IOException e) {
+            LOG.debug("Could not extract classpath entry from URL: {}", url, 
e);
+            return null;
         }
     }
 

Reply via email to