Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package and classpath

 
Nandini Sriram
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
This is my package structure. And I have this inside ' myjava ' folder.
suncertify\db
All files given by the Sun plus LocalDataImpl
suncertify\server
Connection and Factory files plus the interfaces (connection and factory)
suncertify\client
DataClient and my UI
I try to run my program like this:
c:\>set classpath=c:\myjava\
c:\>java suncertify.server.FacImpl <host> <port>
The server is started and it runs...
But when I try to run it from any other directory (even from 'myjava'),
c:\someOtherDir>java suncertify.server.FacImpl <host> <port>
it says: "Data:Request to open a non-existant or inaccessible file db.db"
Please tell me if there's some mistake in my classpath setting or package structure.
Thanks
Nandini
 
Flemming Mertz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Nandini
Sounds to me like you are using a relative path to your file somewhere. If you have the access to your db.db file like this somewhere:
String path = "suncertify/db/db.db";
Then, as far as I recall, it means "/FromWhereIStartTheProgram/" + path, not where the file using the path is. So starting is from anywhere else than the root directory of the app, as you speak about, will prefix your path with that dir. In which case the server of cource can't find your DB file.
Just stating in the readme that the server must be started from the appropriate directory should solve this. Of course there are also better solution, but to be honest, I have not reached that part of the assignment yet. And it's been to long since I used File's for me to remember.
Anyone? ;o)
Regards,
Flemming Mertz
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11888
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nandini & Flemming,
I agree with Flemming as to the probable cause.
[Flemming] Just stating in the readme that the server must be started from the appropriate directory should solve this.

Sounds like a nice simple solution.
Of course there are also better solution ...

Well, there are more user friendly solutions, and more complex solutions. But whether they are "better" is a difficult decision
One solution might be to allow the user to specify the location of the database file, possibly by using a file chooser.
Another option: As long as the user used my executable jar file, I could look at the class path and determine where my jar file was, and from there I could make a reasonable guess at where the database file was likely to be. I then presented that as the default location to the user. Very user fiendly. But way overkill for the project
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic