prograMNewbie
asked on
add a dir to the classpath and read it back from within program
Hi all,
I have a java program thats which loads jpegs from a dir. The dir is stored locally but now the program is to be run on multiple machines. (these machines will have their own jvm of the program). Ive been told to add the directory to my classpath and then read the dir back from within the program. But im not sure how to go about this.
Any ideas?
Thanks
I have a java program thats which loads jpegs from a dir. The dir is stored locally but now the program is to be run on multiple machines. (these machines will have their own jvm of the program). Ive been told to add the directory to my classpath and then read the dir back from within the program. But im not sure how to go about this.
Any ideas?
Thanks
You can't. You could custom class load though
ASKER
I can't
Can't do both?
Why not just place it where all machines can read it?
ASKER
>>Why not just place it where all machines can read it?
I've just been told it has to be done this way. Could I set an environmental variable and then read that variable from within the program?
>>Could I set an environmental variable and then read that variable from within the program?
Yes. Or you could do
java -DimageDir=xxxx YourApp
and read it in the program
Yes. Or you could do
java -DimageDir=xxxx YourApp
and read it in the program
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes ive considered using a program argument and just reading it back through args[].
Is your way better?
An environment variable may be better. Read as above
ASKER
ive got that working thanks,
why do I need the -D in front of imageDir when setting the variable?
It tells it it's an environment variable
ASKER
alright, thanks again
:-)
Perhaps a better approach would be to save the location of the image directory (changeable) in a network file, the location of which would never change. All programs could derive the location by reading that file
Perhaps a better approach would be to save the location of the image directory (changeable) in a network file, the location of which would never change. All programs could derive the location by reading that file
Well, it is not really an environment variable, but a variable to this program's environment.
You might set a real (global) environment variable in Windows or LINUX and then
read it inside the program by System.getenv("imageDir");
Then you don't have to specify it in the command line.
Comes handy when you start your program from a double click: no command line.
You may choose.
;JOOP!
You might set a real (global) environment variable in Windows or LINUX and then
read it inside the program by System.getenv("imageDir");
Then you don't have to specify it in the command line.
Comes handy when you start your program from a double click: no command line.
You may choose.
;JOOP!
>>It tells it it's an environment variable
It's a VM variable really, but you read it as if it were
It's a VM variable really, but you read it as if it were
We agree.
ASKER
>>Comes handy when you start your program from a double click
Im running the program with eclipse so that does'nt apply here.
>>Perhaps a better approach would be to save the location of the image directory (changeable) in a network file
I agree that would be much better and more than likely save copying folders in the future but these programs at least for now are run on different networks.
Thanks all for the comments ;-)
>>but these programs at least for now are run on different networks.
You could read it from a webserver
You could read it from a webserver
ASKER
>>You could read it from a webserver
Yes true, but that is just not an option for me now for various reasons.