Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

eclipse how to access config file

Posted on 2014-02-03
2
Medium Priority
?
446 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 800 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 36

Accepted Solution

by:
mccarl earned 1200 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

636 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