You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/03/06 18:36:32 UTC

(camel) branch main updated: CAMEL-21846: camel-jbang - Add support for running other JVMs such as Eclipse OpenJ9 that does not include JFR flight-recorder

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 9fd8e495f9b CAMEL-21846: camel-jbang - Add support for running other JVMs such as Eclipse OpenJ9 that does not include JFR flight-recorder
9fd8e495f9b is described below

commit 9fd8e495f9b877c050287c915309d0a5757b005b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Mar 6 19:36:12 2025 +0100

    CAMEL-21846: camel-jbang - Add support for running other JVMs such as Eclipse OpenJ9 that does not include JFR flight-recorder
---
 .../org/apache/camel/main/BaseMainSupport.java     | 27 ++++++++++++++--------
 .../java/org/apache/camel/main/KameletMain.java    |  3 ++-
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index f66e39b8a0d..4ea9e09307e 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -680,15 +680,24 @@ public abstract class BaseMainSupport extends BaseService {
                 || "java-flight-recorder".equals(mainConfigurationProperties.getStartupRecorder())
                 || mainConfigurationProperties.getStartupRecorder() == null) {
             // try to auto discover camel-jfr to use
-            StartupStepRecorder fr = ecc.getBootstrapFactoryFinder()
-                    .newInstance(StartupStepRecorder.FACTORY, StartupStepRecorder.class).orElse(null);
-            if (fr != null) {
-                LOG.debug("Discovered startup recorder: {} from classpath", fr);
-                fr.setRecording(mainConfigurationProperties.isStartupRecorderRecording());
-                fr.setStartupRecorderDuration(mainConfigurationProperties.getStartupRecorderDuration());
-                fr.setRecordingProfile(mainConfigurationProperties.getStartupRecorderProfile());
-                fr.setMaxDepth(mainConfigurationProperties.getStartupRecorderMaxDepth());
-                camelContext.getCamelContextExtension().setStartupStepRecorder(fr);
+            try {
+                StartupStepRecorder fr = ecc.getBootstrapFactoryFinder()
+                        .newInstance(StartupStepRecorder.FACTORY, StartupStepRecorder.class).orElse(null);
+                if (fr != null) {
+                    LOG.debug("Discovered startup recorder: {} from classpath", fr);
+                    fr.setRecording(mainConfigurationProperties.isStartupRecorderRecording());
+                    fr.setStartupRecorderDuration(mainConfigurationProperties.getStartupRecorderDuration());
+                    fr.setRecordingProfile(mainConfigurationProperties.getStartupRecorderProfile());
+                    fr.setMaxDepth(mainConfigurationProperties.getStartupRecorderMaxDepth());
+                    camelContext.getCamelContextExtension().setStartupStepRecorder(fr);
+                }
+            } catch (NoClassDefFoundError | Exception e) {
+                if (mainConfigurationProperties.getStartupRecorder() != null) {
+                    throw new IllegalArgumentException(
+                            "Flight recorder is not available in the JVM or camel-jfr is not available on the classpath due to: "
+                                                       + e.getMessage(),
+                            e);
+                }
             }
         }
     }
diff --git a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index 2a443b91d34..e8818feb271 100644
--- a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++ b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -868,7 +868,8 @@ public class KameletMain extends MainCommandLineSupport {
 
     protected String startupInfo() {
         StringBuilder sb = new StringBuilder();
-        sb.append("Using Java ").append(System.getProperty("java.version"));
+        sb.append("Using Java ").append(System.getProperty("java.version")).append(" (")
+                .append(System.getProperty("java.vm.name")).append(")");
         sb.append(" with PID ").append(getPid());
         sb.append(". Started by ").append(System.getProperty("user.name"));
         sb.append(" in ").append(System.getProperty("user.dir"));