Re: Directory Structure for java
On Tue, 2 Jun 2009, Dan Smithers wrote:
On Mon, 1 Jun 2009, Dan Smithers wrote:
I would also like to add a build directory to reduce clutter in the
source directory, but when I try it I get a null pointer exception
accessing the icons directories.
I am compiling this as
javac -O -g -deprecation -d build *.java
and running from the project directory using
java -cp build VTASystem
If the images are being loaded as resources (through the
Class.getResource* methods), then they need to be on the classpath too
(bit weird, but that's how it goes). Do:
yes it is using Class.getResource
java -cp build:icons VTASystem
presumably ; not :
Possibly - i only use unix platforms, where it's a : - is it a ; on
windows?
Assuming that the resource references are written relative to the
project root (/icons/foo.png, /icons/JPEGS/bar.jpg, etc), and that
you're running that command from the project root.
No they aren't. There is a single directory of icons that is used
throughout the code.
Hold on - could you give an example of exactly what the resource paths
look like? If they have a leading slash, they're relative to the project
root (actually, the classpath root - see below), and if they don't,
they're relative to the class on which getResource was called. From what
you say, it sounds a lot like the former.
It works if I compile in the source directory, but I don't like that.
It shouldn't matter where you compile from, only where you run from.
The thing is, when you ask for a resource /foo/bar, the JVM goes through
all the classpath entries and looks for a file called
%CLASSPATH_ENTRY%\foo\bar (using a windows-style expression there!). So,
for it to find your icons, you need to have set the classpath to include
the directory which holds your icons directory. I suspect that when you
run from different places, you're somehow not doing that.
If you're just running, this isn't really easier than using a separate
classpath entry that points to the resource root, but it's convenient
when you make a JAR.
I'm trying out ant. I have a basic build.xml that compiles and makes the
jar, but I still get the problem loading the image resource.
Is there a way of setting up variables for the javac command? something
like
<property name="JFLAGS" value="-O -g -deprecation"/>
<javac srcdir="." destdir="build">
<compilerarg value=${JFLAGS}/>
</javac>
I've tried this but it doesn't work. Am I still thinking too much like make?
Pass - i'll leave this to someone who knows ant better than me to answer.
How do I set up resource directories for the jar command?
Copy the resources into the build directory, using an ant copy task,
before jarring as normal.
tom
--
They Set Up Us The Revolution - Now We Have Set Up It Them Back