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
prograMNewbieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You can't. You could custom class load though
0
prograMNewbieAuthor Commented:

I can't

Can't do both?
0
CEHJCommented:
Why not just place it where all machines can read it?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

prograMNewbieAuthor Commented:

>>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?
0
CEHJCommented:
>>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
0
CEHJCommented:
String imageDir = System.getProperty("imageDir");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
prograMNewbieAuthor Commented:

Yes ive considered using a program argument and just reading it back through args[].
Is your way better?
0
CEHJCommented:
An environment variable may be better. Read as above
0
prograMNewbieAuthor Commented:

ive got that working thanks,

why do I need the -D in front of imageDir when setting the variable?
0
CEHJCommented:
It tells it it's an environment variable
0
prograMNewbieAuthor Commented:

alright, thanks again
0
CEHJCommented:
:-)

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
0
sciuriwareCommented:
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!
0
CEHJCommented:
>>It tells it it's an environment variable

It's a VM variable really, but you read it as if it were
0
sciuriwareCommented:
We agree.
0
prograMNewbieAuthor Commented:

>>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 ;-)
0
CEHJCommented:
>>but these programs at least for now are run on different networks.

You could read it from a webserver
0
prograMNewbieAuthor Commented:

>>You could read it from a webserver

Yes true, but that is just not an option for me now for various reasons.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.