This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Package and classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Package and classpath" Watch "Package and classpath" New topic
Author

Package and classpath

Nandini Sriram
Ranch Hand

Joined: Jul 04, 2003
Posts: 132
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


Discipline, Dedication and Determination define Destiny.
Flemming Mertz
Greenhorn

Joined: Jul 15, 2003
Posts: 11
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

Joined: Mar 28, 2003
Posts: 11437
    
  87

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
 
subject: Package and classpath