Skip to content

Auto-discover/load RouteBuilder from Maven dependency (Jar) #6502

@Tonatiuh011

Description

@Tonatiuh011

Requirement

Hi,

Topic from Zulip: #camel-k > Auto-discover/load RouteBuilder from Maven dependency (Jar)

I have some Java Camel routes packaged in a Maven artifact that I would like to run in my integrations.

Specs:

  • Camel K: 2.9.0

  • Repository: Nexus (private maven repo)

Current Workaround: To start the routes, I have to use an additional "loader" Java class to manually wire them:

import org.apache.camel.builder.RouteBuilder;
import org.tnt.camel.MyRouteBuilder;

public class Loader extends RouteBuilder {
  @Override
  public void configure() throws Exception {
      getContext().addRoutes(new MyRouteBuilder());
  }
}

The Java route inside my Maven artifact looks like this:

package org.tnt.camel;

import org.apache.camel.builder.RouteBuilder;

public class MyRouteBuilder extends RouteBuilder {
    public void configure() {
        from("timer:test")
                .setBody().constant("Hi from jar!")
                .log("${body}");
    }
}

I run this integration using the following command:

kamel run Loader.java test.camel.yaml --name test-mvn -d mvn:org.tnt.camel:tnt-camel:1.0.0

The Question: All works good, but I was wondering if there is an alternative way to tell Camel K to auto-discover or scan for routes in the classpath at runtime?

I am looking for something similar to camel.main.routes-include-pattern so I can just point to the JAR and avoid writing the Loader.java wrapper class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions