It's not a secret anymore!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Access files outside jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Access files outside jar file" Watch "Access files outside jar file" New topic

Access files outside jar file

Ranch Hand

Joined: Apr 05, 2002
Posts: 36
your suggestion please.
1.when run java -jar client.jar db.db. Exception was thrown.
2.when I access remote server by run client.jar and try to show online help but client.jar can not find userguide.html.
I put client.jar, db.db, userguide.html in the same dir starting\,
summary: I can not access files outside client.jar.
thanks in advance
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17271

Consider this. a jar file is the start of a path. The files that are inside the jar file have further path information. When you run the jar file with java -jar client.jar you are telling java that you have a manifest file in there that will point to the main class. However, you have not told java the classpath. This is really important to access outside files. Becuase java still needs to know where to find them, and it looks in the classpath, if the classpath is not set, and the files aren't where the classpath is set, then you will get your error.
What is your classpath?

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ranch Hand

Joined: Apr 05, 2002
Posts: 36
Thank you very much. got your idea.
somebody's online.html is put in a dir. starting\doc\online.html. the classpath is set at starting\. when I put file in classpath I can access them. but if I put them in a dir which in the classpath I don't know how to access them. could you give me some idea please
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Access files outside jar file
It's not a secret anymore!