Search code examples
apache-camelspring-camel

Camel read file from classpath resource?


I have a file on the classpath at "resources/file.txt" in a Spring Boot app.

How do i reference this in a Camel route?

I have tried:

from("file:resource:classpath:?fileName=file.txt") and variations on it. Nothing seems to work.

Any workaround here pls?

Thanks


Solution

  • You cannot use the file component for this, as its intended for reading via java.io.File API - eg regular files on file systems. Also many of the options are for file specific tasks such as read locks, moving files around to avoid reading them again after processing, deleting the file(s), and scan into sub folders etc. All kind of tasks needed when exchanging data via files.

    To read resources within JAR files, then you Java API or the stream component.