Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

where to put properties filesthat are being used by external customized jar files

Avatar

Level 3

we have dependency on external customized jar file and that jar file is dependent on some property files. So where should we keep these property files ? We tried to keep it ..\crx-quickstart\conf on this path but its giving  "Can't find bundle for base name environment, locale en_US" this exception

8 Replies

Avatar

Level 10

Could you please explain your use case?

Are these customized jar files hosted in AEM as bundles? Are you using AEM jar or AEM war file in a container?

Avatar

Level 3

we have dependency on customized external jar (which is belong to some other team) .The jar is having dependency on property files which are not bundles within jar.They are sharing property files separately along with jar.They are loading property files in their jar using getBundle() from  ResourceBundle Class which is java library class.Now we are facing issue where to keep those property files?

we tried with different approaches
* by keeping property files in src/main/resources in aem.core project
* placed in ..\crx-quickstart\conf

Both approaches didn't work well...
Please Do help me...

Avatar

Level 10

To me, that doesn't seem a recommended way of working with AEM.

You could also use BundleContext to read the properties file. Put the file in bundle classpath.

Try couple of things:

package the property file within the jar file and add relative path of file in bundle classpath entry in manifest file of that bundle.

if you want to use /conf path to read the property file then use SystemClassLoader

java - How to use a property file in an OSGi bundle - Stack Overflow

cq5 - Using properties file in osgi bundle - Stack Overflow

Adobe CQ/Adobe AEM: How to work with Configurations in CQ

Avatar

Level 10

When working with OSGi bundles that use 3rd party JARs (that are located in the Maven Repository), you can embed the 3rd party JAR (for example, Simple JSON JAR) into a separate bundle and deploy to AEM. See this community article/video for details.

http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html

Do not place the 3rd party JAR into a path in the JCR. Wrap it into an OSGi bundle and deploy to AEM - as we show Simple JSON JAR in the above article.

Avatar

Community Advisor

As Gaurav said it's not the recommended AEM way although would be helpful to understand more if you provide the lines of code that show how property file being accessed or read?

Avatar

Level 3

following code is used in dependent jar to load property files(The jar is binded with out property files)

ResourceBundle rb = ResourceBundle.getBundle("property file name");

String keyDetail = rb.getString("Key name");

we have to use dependent jar in our AEM project so we converted jar as OSGI bundle without property files, we cannot ask other team to use BundleContext to load property files since so many applications are using same jar.

is there any way to load external jar along with property files in AEM server

Avatar

Community Advisor

If another team is not including property file in the same jar then you can try below code.

Store config.properties file somewhere on the server and read it via InputStream in your OSGi custom bundle

Properties properties = new Properties();

InputStream inputStream = new FileInputStream("D:/properties/config.properties");

properties.load(inputStream);

String departmentName = properties.getProperty("departmentName");