# Camel CLI - Tips and Recipes

A collection of productivity shortcuts and advanced techniques for working with the Camel CLI.

## Run from clipboard

Run a route directly from the OS clipboard — copy some code, then run it:

```bash
camel run clipboard.yaml
```

The extension tells the CLI which DSL the clipboard content uses (`yaml`, `java`, `xml`).

You can also run from clipboard in dev mode for live reload:

```bash
camel run clipboard.yaml --dev
```

Edit your code, copy it again, and Camel reloads automatically.

## Run with inline code

For quick one-liners, pass the route directly on the command line:

```bash
camel run --code='from("kamelet:beer-source").to("log:beer")'
```

Limitations:

-   Java DSL only
    
-   Wrap code in single quotes so you can use double quotes inside
    
-   All routes must fit in a single `--code` parameter
    

From Camel 4.7, `--code` can also reference a `.java` file that contains bare route definitions (no `public class` wrapper):

_Java-only: bare route definition for --code_

```java
from("timer:java?period=1000")
    .setBody()
        .simple("Hello from ${routeId}")
    .log("${body}");
```

```bash
camel run --code=quick.java
```

## Interactive prompt for placeholder values

Run with `--prompt` to have Camel ask for missing values at startup:

```bash
camel run foo.java --prompt
```

Camel will prompt for each unresolved \`{{placeholder}}\` in the terminal. Placeholders with default values (e.g. \`{{time:1000}}\`) can be accepted by pressing Enter.

This is useful for prototypes where you want users to enter custom values quickly. Values can also be pre-configured in `application.properties`.

## Stub components

When troubleshooting a route that uses components you cannot connect to (JMS brokers, databases, etc.), stub them out:

```bash
camel run myroute.java --stub=jms
```

Camel replaces the stubbed component with an in-memory substitute, keeping the original endpoint URIs. You can then send test messages with:

```bash
camel cmd send --body='Something here'
```

Other stub options:

```bash
camel run myroute.java --stub=jms:inbox    # stub a specific endpoint
camel run myroute.java --stub=jms,sql      # stub multiple components
camel run myroute.java --stub=remote       # stub all remote components
camel run myroute.java --stub=all          # stub everything
```

The `remote` flag uses the Camel catalog to determine which components connect to external systems.

Use `camel cmd stub` to list stubbed endpoints, and `camel cmd stub --browse` to browse their messages.

## Run from GitHub

Run a route directly from a GitHub repository:

```bash
camel run github:apache:camel-kamelets-examples:jbang/hello-java/Hey.java
```

Or use the full HTTPS URL — copy it from your browser:

```bash
camel run https://github.com/apache/camel-kamelets-examples/tree/main/jbang/hello-java
```

Wildcards work too:

```bash
camel run https://github.com/apache/camel-kamelets-examples/tree/main/jbang/languages/rou*
```

### Run from GitHub gists

Gists are a quick way to share small Camel routes:

```bash
camel run https://gist.github.com/davsclaus/477ddff5cdeb1ae03619aa544ce47e92
```

A gist can contain multiple files (routes, properties, Java beans) — the CLI gathers them all.

## Download from GitHub

Download examples from GitHub to local disk for editing:

```bash
camel init https://github.com/apache/camel-kamelets-examples/tree/main/jbang/dependency-injection
camel run *
```

Use `--directory` to download into a specific folder:

```bash
camel init https://github.com/apache/camel-kamelets-examples/tree/main/jbang/dependency-injection --directory=myproject
```

Single files and gists work the same way:

```bash
camel init https://github.com/apache/camel-kamelets-examples/blob/main/jbang/hello-yaml/hello.camel.yaml
camel init https://gist.github.com/davsclaus/477ddff5cdeb1ae03619aa544ce47e92
```

## Upload files via HTTP

When running with `--source-dir`, `--console`, and `--dev`, you can upload, modify, or delete source files over HTTP:

```bash
camel run --source-dir=mycode --console --dev
```

Upload or update a file:

```bash
curl -T bar.java http://0.0.0.0:8080/q/upload/bar.java
```

Delete files (wildcards supported):

```bash
curl -X DELETE http://0.0.0.0:8080/q/upload/bar.java
curl -X DELETE http://0.0.0.0:8080/q/upload/*.java
curl -X DELETE http://0.0.0.0:8080/q/upload/*
```

## Maven configuration

By default, Camel CLI loads `~/.m2/settings.xml` for Maven mirrors, credentials, and repositories.

You can override the settings file location:

```bash
camel run foo.java --maven-settings=/path/to/settings.xml --maven-settings-security=/path/to/settings-security.xml
```

Or disable Maven settings entirely:

```bash
camel run foo.java --maven-settings=false
```

For encrypted passwords in Maven settings, configure a master password with `mvn -emp`, store it in `~/.m2/settings-security.xml`, then encrypt repository passwords with `mvn -ep`. See the [Maven encryption guide](https://maven.apache.org/guides/mini/guide-encryption.md) for details.

## Running a Maven based project

Camel CLI can run an existing Maven-based project:

```bash
camel run pom.xml
```

The runtime is detected from the `pom.xml` (Spring Boot, Quarkus, or Camel Main), and the project is built and run with Maven (`spring-boot:run`, `quarkus:dev` with `--dev` or `quarkus:run`, and `camel:run`). The project itself is not modified: the `camel-cli-connector` dependency is injected into a temporary `camel-jbang-run-pom.xml`, so the application shows up in `camel ps`, and the application logs to a file in `~/.camel` so `camel log`, the TUI and the MCP server can read the logs the same as for any other `camel run`: `<pid>.log` for Spring Boot, and `<name>.log` for Quarkus and Camel Main, whose logging is configured before the process id is known (`<name>` is `camel.main.name` from the project’s `application.properties`, or else the Maven artifactId, and is passed to the application as its name). The temporary files are removed when the application stops.

The options `--profile`, `--port`, `--prop`, `--max-seconds`, `--max-messages`, `--max-idle-seconds`, `--jvm-args` and `--jfr` are passed to the application (Camel Main runs inside the Maven JVM, so `--jvm-args` and `--jfr` are set via `MAVEN_OPTS`). A Camel Main project is expected to use log4j2 for logging (the same as `camel export --runtime=main` generates).