Solved

eclipse how to access config file

Posted on 2014-02-03
2
409 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
[X]
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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 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