Solved

eclipse how to access config file

Posted on 2014-02-03
2
395 Views
Last Modified: 2014-02-06
i have a ehcache.xml file in resources/META-Inf folder, how can i reference this file programmatically?

i tried CacheManager.create("classpath:META-INF/ehcache.xml");
CacheManager.create("META-INF/ehcache.xml");
CacheManager.create("/META-INF/ehcache.xml");

nothing but the full path (hardcoded) works. thanks.
0
Comment
Question by:mmingfeilam
2 Comments
 
LVL 6

Assisted Solution

by:Mahesh Bhutkar
Mahesh Bhutkar earned 200 total points
Comment Utility
i have a ehcache.xml file in resources/META-Inf folder
You have to add resources folder inside Source Tab of Java Build Path of your project.

Related to ehcache You may refere code samples from http://ehcache.org/documentation/code-samples

Some good recipes at http://ehcache.org/documentation/2.4/recipes/
0
 
LVL 35

Accepted Solution

by:
mccarl earned 300 total points
Comment Utility
Just to elaborate on why it isn't working, the method that you are using, ie. CacheManager.create(String), passes that string to a java.io.File constructor which means that it attempts to find the file in the filesystem. This is why the full path works, and also a relative path would work as long as you know the current working directory when your program is executed. A better solution probably would be to load the file from the classpath (which it looks like what you were trying to do). So assuming that the META-INF folder is being included in your classpath, you can use the following to load it from there...
URL configUrl = getClass().getResource("/META-INF/ehcache.xml");
CacheManager cm = CacheManager.create(configUrl);

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 69
countHi challenge 25 84
changePi Challenge 15 75
Printing to a specific printer tray (HP 806dn printer) 3 62
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now