Discussion:
classpath configuration - adding a directory
(too old to reply)
Andrew Gray
2005-06-13 06:27:49 UTC
Permalink
Could anyone help me with this.

I have a requirement to add (the contents of) a directory to the java classpath. This directory is a 'resources' directory within a project, and exists alongside the 'class'es directory.

Looking in the JBuilder (2005) interface - it looks as if the project output directory is automatically added to the cp, and you can also add other projects/libraries to the cp (Project Properties -> Paths), but I cannot see a way of adding another directory in the current project to the classpath.

I can use 'Configure Libraries' to assign multiple directories/archives to a given project, which I can then add to the cp of a different project, but presumably this does not help, as if I were to add the resource area in this way, and then make a project depend on itself, then the class archive would be added aswell.

The only way I can see at the moment is to define a seperate Library eg 'MyProject-Resources' alongside 'MyProject' in Configure Libraries - which just references the resources directory, and then add this to the path references of 'MyProject' - however, this looks like a nasty hack.

Is there a better way of doing this ?

Thanks in advance,

Dr Andrew Gray
Paul Furbacher [TeamB]
2005-06-13 16:10:11 UTC
Permalink
Post by Andrew Gray
I have a requirement to add (the contents of) a directory to the
java classpath. This directory is a 'resources' directory within a
project, and exists alongside the 'class'es directory.
Looking in the JBuilder (2005) interface - it looks as if the
project output directory is automatically added to the cp, and you
can also add other projects/libraries to the cp (Project Properties
-> Paths), but I cannot see a way of adding another directory in
the current project to the classpath.
Assuming you have resources (images, properties files, etc.?)
in a directory structure other than "src", you could try the
following.

1. Add another source directory pointing to your resources dir
in Project Properties > Paths.

<project dir>
/bak
/doc
/classes
/src
/resources <-- at same level as "src"

2. In Project Properties > Build > Resources, make sure that you
change to "Copy" any file extension which must be copied from
the /resources folder.

3. Compile and verify that your resources have been copied to
the /classes folder.


However, most often, resources such as images and properties
files should be located relative to the classes which refer
to them. So, in most cases, these resource belong in the
appropriate directory in the "src" path of your project,
not in a separate path. That is, if a class depends on a
properties file to lookup initial values, and uses

URL resUrl = this.getClass().getResource("values.properties")/

the "value.properties" should be located in the same folder
as the source for this particular class. JBuilder will automatically
copy .properties files to the class output directory, and you can
add to the resource filetypes to be copied as in Step #2 above.
--
Paul Furbacher (TeamB)

Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Loading...