mule/java – reading a property file which is inside of jar dependency from java class

Here my requirement is, I have created one mule application which has java class. Some of the values which I don’t want to keep it as a hard-coded so I am trying to externalize it. I kept this values in mule-app.properties file and used FileInputStream as below.

String propFileName = "src/main/app/mule-app.properties"
Properties property = new Properties();
property.load(new FileInputStream(propFileName));

But this code needs to be deployed on CloudHub; there its failing saying that file not found. I Tried with give path of the file name as

String propFileName = "target/classes/mule-app.properties"

for both the cases its running fine locally but gives same results on CloudHub as “File Not Found”.

What could be the solution?

Another thing is I have a common code in which we are keeping all the properties related to different environment. Packaging of this common code is in the form of jar. So, can I keep properties which I am using in above code and read it from jar itself.

If Yes, then How?

If you want to deploy in cloudhub and externalize your properties file better use Cloudhub properties tab to externalize the values.
ref:- https://docs.mulesoft.com/runtime-manager/deploying-to-cloudhub#properties-tab

And in Java class you can pick the properties value using :- System.getProperty(“yourpropertykey”)
simple as that 🙂

Regarding keeping properties file in common jar app, you need to use <context:property-placeholder/> to pick up the properties file from the classpath of the common jar application and can use it in your host application mule flow