Java 在类路径中找不到Camel属性文件

Java 在类路径中找不到Camel属性文件,java,properties,apache-camel,Java,Properties,Apache Camel,我试图加载资源:src/com/company/my.properties,但在类路径上找不到它 错误 骆驼核心:2.18 骆驼属性阅读参考: my.properties文件包含“fromroute”键: fromroute=文件:/a/b 下面的代码片段显示了我如何尝试加载该文件 PropertiesComponent pc = new PropertiesComponent(); pc.setLocation("classpath:com/company/my.properties

我试图加载资源:src/com/company/my.properties,但在类路径上找不到它

错误 骆驼核心:2.18 骆驼属性阅读参考: my.properties文件包含“fromroute”键:

fromroute=文件:/a/b

下面的代码片段显示了我如何尝试加载该文件

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

....
  from("properties:{{fromroute}}")
....    
my.properties文件应移到src/main/resources,而不是src/com/company 并更新设置位置路径:


为了让类加载器找到资源,它需要位于src/main/resources/中,例如在您的示例中:src/main/resources/com/company/my.properties,否则资源将不会出现在JAR文件中,并且在运行时无法访问

根据用于加载资源的类加载器的类型,您需要包含或排除包名

例如:

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

Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/company/my.properties");

为了让类加载器找到您的属性文件,它应该位于src/main/resources中的某个位置。或者在您的情况下,SRC/Mault/Reals/COM/Copys.@ LUC14N0感谢您的反馈,我将属性文件移到类文件夹中,您是否考虑了问题的答案?
pc.setLocation("my.properties");
getClass().getClassLoader().getResourceAsStream("my.properties");

Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/company/my.properties");