>>I have the following code in an application:
>> URL url = Thread.currentThread().getContextClassLoader()
[quoted text clipped - 18 lines]
> your post that you have your project properly set up with src as a source
> directory and bin as the output directory.
Yup, that's me. I not trying any tricks.
> When Eclipse builds it will compile the java files in your src directory and
> put them into your bin directory, but it will also copy any other files in
> the src directory such as xml files, property files, and graphics to the bin
> directory.
Oh, very interesting!
> At runtime you shouldn't be accessing the file in the src
> directory.
Didn't want to access it in the src really, just wanted the code to
find the latest .ini file.
> Anything in the class path for the project besides other jars and
> projects should be in the bin directory.
So should I have them in the src and let them be copied or should
I place them in the bin dir? When you say "should have" is that the result of
my starting with them there, some setting to say 'sure go ahead and move them
there just before running' or because of some built-in behavior? Is there
some list it recognizes as 'to be copied' before running?
> If you are trying to write to the file then you shouldn't be using
> getResource as that is designed for reading.
I'm certainly not writing to it in Java! Sorry If I wasn't clear. When
I said I was "playing" with the file, I meant I was making various entries
in the INI at development time with an editor to make the program work at
runtime. The 'playing' involved maintainomg and extending whatever
was in the INI file not some unorthodox feedback loop involving writing
back an INI file at runtime.
> If you have files in ini that you need to access as a resource then you
> probably need to make ini a source directory or move the ini folder into the
> src folder.
And then I don't need to put /src/ini (or /resource) in the CLASSPATH?
When you say 'make it a source dir.' what do mean with regard to Eclipse?
Sorry about the confusion, I was using ant scripts in JSP projects
to put everything together for runtime in my measly attempts in Eclipse
before, so am not familiar with the default behavior a plain Java
application with regard 'other files.'
thanks for your help,
-Paul
Dale King - 04 Nov 2003 18:18 GMT
> >>I have the following code in an application:
> >> URL url = Thread.currentThread().getContextClassLoader()
[quoted text clipped - 42 lines]
> there just before running' or because of some built-in behavior? Is there
> some list it recognizes as 'to be copied' before running?
Yes, you should put them in a source folder and it will get copied to the
bin directory. That is built-in behavior of the JDT. See this quote from the
FAQ for the JDT:
"If your Java project is using source folders, then in the course of
compiling the source files in the project, the Java compiler copies non-Java
resources to the output folder as well so that they will be available on the
class path of the running program. To avoid certain resources to be copied
to the output location you can set a resource filter in the compiler
preferences: Window > Preferences > Java > Compiler > Build Path"
> > If you are trying to write to the file then you shouldn't be using
> > getResource as that is designed for reading.
[quoted text clipped - 5 lines]
> was in the INI file not some unorthodox feedback loop involving writing
> back an INI file at runtime.
Then getResource is probably what you want.
> > If you have files in ini that you need to access as a resource then you
> > probably need to make ini a source directory or move the ini folder into the
> > src folder.
>
> And then I don't need to put /src/ini (or /resource) in the CLASSPATH?
Correct.
> When you say 'make it a source dir.' what do mean with regard to Eclipse?
Yes, either put it into the existing source directory or else you can make
the existing directory an additional source directory. You can have multiple
source directories. You might want your resources separate from your Java
source files. I personally don't, but it is up to you.
> Sorry about the confusion, I was using ant scripts in JSP projects
> to put everything together for runtime in my measly attempts in Eclipse
> before, so am not familiar with the default behavior a plain Java
> application with regard 'other files.'
--
Dale King