Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Base Directory

 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That got it.
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Selador:
Thanks! That got it.


Oops, sorry, I hadn't seen your post.
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I'm an idiot. Its pretty in the latter document listed (about Policy File syntax) what to do.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic