Skip to content

refactor: move MyRouteBuilder to standalone class in java-lambda example#158

Merged
davsclaus merged 2 commits intoapache:mainfrom
jomin7:main
Mar 2, 2026
Merged

refactor: move MyRouteBuilder to standalone class in java-lambda example#158
davsclaus merged 2 commits intoapache:mainfrom
jomin7:main

Conversation

@jomin7
Copy link
Contributor

@jomin7 jomin7 commented Mar 2, 2026

This PR refactors the java-lambda example by moving the MyRouteBuilder inner class from MyApplication.java into its own standalone file, MyRouteBuilder.java.

The Problem:

Previously, MyRouteBuilder was defined as a package-private inner class. While mvn clean install passed (compilation was successful), running the example via mvn camel:run triggered a java.lang.IllegalAccessException.
This occurred because Apache Camel’s ObjectHelper uses reflection to instantiate routes. In modern Java runtimes (Java 17+), reflection-based access to non-public inner classes from a different package is restricted.

The Fix:

Created MyRouteBuilder.java as a public standalone class.
Removed the nested MyRouteBuilder class from MyApplication.java.
Verified that mvn camel:run now starts the Camel context successfully without reflection errors.

Fixes IllegalAccessException during 'mvn camel:run' by ensuring the
RouteBuilder is public and accessible for reflection.
@jomin7
Copy link
Contributor Author

jomin7 commented Mar 2, 2026

Hi @davsclaus , thank you for the review. I have updated the PR to include the ASF license header and fixed the indentation of the route to respect the EIP patterns as requested. I've also verified the fix again with mvn camel:run.

@davsclaus davsclaus merged commit 34d6060 into apache:main Mar 2, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants