Advertisement

07.10.2008 at 03:32AM PDT, ID: 23553188
[x]
Attachment Details

How to use property files as resources

Asked by apollonius_tyana in Open Source Programming, J2EE, Java Standard Edition

Tags: java

I've got an application where I need to store some config parameters. Property files make perfect sense for my case. But I don't want to access files directly because there's a good chance that the app will be used in a web or JavaEE environment where I'll not have direct file access.

I've been ripping my hair off for hours but I always get resource not found errors. I'm using Netbeans 6.1 and I'm sure the properties file get packaged in the jar file.

My code is below. I've got a config.properties in the same src directory with my class and it gets packaged in the jar.

Looking forward to responses. I think I've got so blind not to see the obvious.

Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
package mypackage;
 
import java.net.URL;
 
public class MyClass {
 
    public static void main(String[] args){
        URL resURL =  MyClass.class.getClassLoader().getResource("config.properties");
        System.out.println(resURL);
    }
    
}
 
Loading Advertisement...
 
[+][-]07.10.2008 at 03:38AM PDT, ID: 21971954

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 03:47AM PDT, ID: 21971994

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 03:50AM PDT, ID: 21972007

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 03:56AM PDT, ID: 21972041

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 04:02AM PDT, ID: 21972058

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Open Source Programming, J2EE, Java Standard Edition
Tags: java
Sign Up Now!
Solution Provided By: Bart_Cr
Participating Experts: 2
Solution Grade: B
 
 
[+][-]07.10.2008 at 04:14AM PDT, ID: 21972115

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 04:20AM PDT, ID: 21972140

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.10.2008 at 04:30AM PDT, ID: 21972186

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 04:47AM PDT, ID: 21972289

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.10.2008 at 07:25AM PDT, ID: 21973698

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628