0

I am tring to load the resource: src/com/company/my.properties, but it can't be found on the classpath.

Error

Failed to create route route1: Route(route1)[[From[properties:{{fromroute}}]] ->
[Choice[[When[... because of Failed to resolve endpoint: properties://%7B%7Bfromroute%7D%7D due to:
Properties file com/company/my.properties not found in classpath
  • camel core:2.18
  • camel properties read refer : Doc

The my.properties file contains a 'fromroute' key:

fromroute=file:/a/b

The following snippet shows how I'm trying to load the file.

PropertiesComponent pc = new PropertiesComponent();
pc.setLocation("classpath:com/company/my.properties");
context.addComponent("properties", pc);

....
  from("properties:{{fromroute}}")
....    
Community
  • 1
  • 1
user881703
  • 1,111
  • 3
  • 19
  • 38

2 Answers2

1

my.properties file should be moved in to src/main/resources (not src/com/company) and update the setLocation() path:

pc.setLocation("my.properties");
Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
user881703
  • 1,111
  • 3
  • 19
  • 38
0

For the classloader to find a resource, it needs to be located in src/main/resources/, e.g. in your case: src/main/resources/com/company/my.properties, otherwise the resource won't end up in the JAR file and its not accessible at runtime.

Dependent on the type of ClassLoader you're using to load the resource, you either need to include or exclude the package name.

For example:

getClass().getClassLoader().getResourceAsStream("my.properties");

Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/company/my.properties");
Luciano van der Veekens
  • 6,307
  • 4
  • 26
  • 30