Solved

eclipse how to access config file

Posted on 2014-02-03
2
403 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 88
eclipse apache tomcat admin console 52 97
by zero exception 10 40
Java string replace 11 46
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

770 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