File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Base Directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Base Directory" Watch "Base Directory" New topic
Author

Base Directory

Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
If I have a .class file that creates a File object, and the URL for the File object is not fully qualified, where is the file expected to reside? What about for .jar files?

For .class files, it appears to be the first nonpackage related folder, but for .jar files, I can't figure it out.

Thanks,

Andy
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8925
    
    9

From the API documentation for java.io.File:
A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
The reason I ask is because I have a .policy file that doesn't seem to want to be read in by the system. I've broken down and changed the java.policy file, which is a horrible idea, but makes it work. Neither the command line -Djava.security.policy=<argument> nor the System.setProperty("java.security.policy", <argument> method work. I haven't tried the absolute path of the file.

I guess what the question is asking is: where does the relative path start for both packaged classes and .jar files?

At the beginning of the package folders? In the same directory as the .jar? Or does it have to be in the .jar file? I can't get any of the .jar related options above to work.
Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
Thanks! That got it.
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Andy,

This may help you out:
http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html

So, if you are using -D option, the relative path to the file should be somewhere accessible from your the current directory, as Joe pointed out.

Hope it helps,

Rodrigo
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
Originally posted by Andy Selador:
Thanks! That got it.


Oops, sorry, I hadn't seen your post.
Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
Well, it turned out the pathname wasn't the problem

When setting .policy files, be careful what you set the codeBase to.

I set it to the .jar file I am running the application from (no libraries), and it did not work. I deleted out the codeBase property, and suddenly everything is golden.

I look through that Policy File document. It might have some hints to whats not working right.
Andy Selador
Ranch Hand

Joined: May 02, 2008
Posts: 34
Ok, I'm an idiot. Its pretty in the latter document listed (about Policy File syntax) what to do.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Base Directory