• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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
0
prograMNewbie
Asked:
prograMNewbie
  • 9
  • 7
  • 2
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now