Solved

Netbeans Java Classpath, Accessing property file outside package in seperate directory

Posted on 2013-01-04
3
450 Views
Last Modified: 2013-01-05
I am trying to move my resource file out of my jar file to an independent conf folder and appear to be having classpath issues. Initially, I would like to get running in my Netbeans project and have changed the classpath from the project properties.libraries.run tab. From here, I selected the Add jar/Folder and provided an absolute path with the absolute path selected. Is this correct? Why will this not work within Netbeans 7.2.1?

String resource_file = "project_config.xml";
InputStream in = this.getClass().getResourceAsStream(resource_file);
 if (in == null) {
        throw new IOException("Error reading resource file:" + resource_file);
  }
0
Comment
Question by:1240
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 350 total points
ID: 38745491
You can't really treat resources like that. Normally, they should not be outside a jar, unless you need to also write to them, in which case, they should be treated and addressed as files.
0
 

Author Closing Comment

by:1240
ID: 38745681
Thanks for the info
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 38746715
:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
ejb entity bean example 2 12
hashmap order 17 37
Java 8 to Java 6 8 20
Running JavaFX on the Raspberry Pi 27 40
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

856 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