Link to home
Start Free TrialLog in
Avatar of stockblocks
stockblocks

asked on

Can Java source code know it's parent file and package names without explicitly defining static String's?

I'm beginning to use JBuilder 2005 for servlet programming.

I often embed references to the source filename (and associated package it belongs to) when reporting error exceptions.  Currently, I have private static String vars named -- appropriately -- CLASS_NAME and PACKAGE_NAME.

Is there a better way?  I was wondering if there was some magical code call that automatically identifies their names.  If not a JDK call, but perhaps a JBuilder macro-like call that can be embedded in my .java files (for example -- and I'm making this up --  #CLASSNAME#.)
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Use log4j. It will report the class and package which logged the message
ASKER CERTIFIED SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stockblocks
stockblocks

ASKER

Excellent.  I see that getClass().getName() reports both package and class names together, which is perfect!

Should have known this all along. Thanks!

SB
glad to help
Log4j is the de facto standard for logging - i'd use it if i were you ;-)
CEHJ,  sorry -- thanks for the tip! I'll google it to learn more.