Java/Ant/Eclipse Question

R

Rhino

I've finally got my logging issue just about sorted out but there's one
thing that still bothers me.

(It turns out that I was trying to write logs to a directory that didn't
exist and the logging code in java.util.logging doesn't create the
directories for you. I suppose this is reasonable behaviour, all things
considered.)

By experimenting, I've found that when I specify a simple file name, like
baz.log.xml, WITHOUT A PATH in my FileHandler instantiation, and then
execute the program in Eclipse, the log will get created in my Project/xml
directory. That's not really where I want it - I'd prefer it written to my
Project/log directory - so I've been experimenting with trying to write the
file name in such a way that the log gets written to my Project/log
directory.

If I specify the path as "..\\log\\baz.log.xml" and execute the code via an
Ant build within Eclipse, it works perfectly. However, when I execute the
code as a Java application, the JVM complains that it doesn't like that
path. Why am I getting different behaviour in these two situations?

What can I do to make my class write its logs to Project/log and have that
work regardless of whether I execute as a Java application, as an Ant Build
within Eclipse, or even as an Ant Build outside of Eclipse? Is there a
setting I need to change in Eclipse to make this work when running as a
Java application?

I am using Windows XP Professional with SP2. Eclipse is at the 3.5.2 level.
Ant is at the 1.7.1 level.
 
M

markspace

Rhino said:
Why am I getting different behaviour in these two situations?


Well, probably because the situations are different. One is being
executed with the current directory set to your Eclipse project, and the
other is where ever you execute the Java application from. Hence,
relative path names probably aren't going to work.

> Is there a
setting I need to change in Eclipse to make this work when running as a
Java application?


Probably, you should define a system property (-Dmy.prop.here) and set
it to what path you want use. Use that from both Eclipse and Ant to set
the path to an appropriate value for a development environment.

Then when the property is missing, default to a more "application-like"
behavior. Read the path from a config file, or let the user set it, or
read the path from the Preferences API. Here you will likely need a
full path.
 
R

Rhino

Well, probably because the situations are different. One is being
executed with the current directory set to your Eclipse project, and the
other is where ever you execute the Java application from. Hence,
relative path names probably aren't going to work.
Fair enough. Thank you!



Probably, you should define a system property (-Dmy.prop.here) and set
it to what path you want use. Use that from both Eclipse and Ant to set
the path to an appropriate value for a development environment.

Then when the property is missing, default to a more "application- like"
behavior. Read the path from a config file, or let the user set it, or
read the path from the Preferences API. Here you will likely need a
full path.
That sounds like great advice. Thanks again!
 
R

Rhino

Well, probably because the situations are different. One is being
executed with the current directory set to your Eclipse project, and the
other is where ever you execute the Java application from. Hence,
relative path names probably aren't going to work.




Probably, you should define a system property (-Dmy.prop.here) and set
it to what path you want use. Use that from both Eclipse and Ant to set
the path to an appropriate value for a development environment.

Then when the property is missing, default to a more "application- like"
behavior. Read the path from a config file, or let the user set it, or
read the path from the Preferences API. Here you will likely need a
full path.

Thank you VERY much! That solved my problem very nicely!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top