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

Current Working Directory?

 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suncertify.properties must be located in the current working directory. I will like to confirm it it means the location where runme.jar is located.
 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are incorrect. It means whatever directory you run the runme.jar file from...which doesn't have to be the directory where it's located (for example. if you have it in your CLASSPATH, you can run it from anywhere).
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how will you know where the user is running the JAR file? Supposed I use a File object. Do you mean that this alone will suffice?

 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a FileReader and FileWriter to read and write my properties file.
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that means the path is correct?
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I read this requirement is:

The suncertify.properties file must be in the current working directory, which is available as a system parameter called user.dir. If the file does not exist, create it.
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if I'm doing anything wrong. I created a sample JAR file, and set the directory which contains that JAR file in the classpath. I tried running the JAR file somewhere else, but it doesn't work. It's called "runme.jar", and I placed it in my root folder (C:\). I place "C:\" in the classpath, then I tried running the JAR file somewhere else with:

java -jar runme.jar

It doesn't work. I tried putting "C:\runme.jar" in the classpath too, but it doesn't work too.

By the way thanks for the "user.dir" solution. I've forgotten that such a property exists.
 
David Abramowicz
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...

I did not see any musts regarding creating a new config file if it doesn't exist.

Did you guys read it like that?

If the config file is put where the runme.jar is located, and an error message if the file can't be found (saying suncertify.properties is not in the current directory) should suffice, surely?

Opinions?

Cheers /Dave
 
David Abramowicz
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... This thread:

http://www.coderanch.com/t/185901/java-developer-SCJD/certification/They-faild-me-don-know

is certainly contradictory to my theory. Seems some poor lass failed due to not auto-creating a suncertify.properties...

/Dave
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David Abramowicz:
Hi...

I did not see any musts regarding creating a new config file if it doesn't exist.

Did you guys read it like that? ...


Yes, I read the configuration and packaging requirements to require that the program must be able to start in its default mode using what is specified in the packaging, which does not include a properties file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic