Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

eclipse how to access config file

Posted on 2014-02-03
2
406 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
ID: 39831637
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
ID: 39832235
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 52
How to convert from xls to xlsx using java 7 55
ejb on wildfly 5 30
ejb message driven bean mdb creation steps 2 16
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

809 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