Link to home
Start Free TrialLog in
Avatar of inditrozen
inditrozen

asked on

Absolute path for the class at runtime.

Hi All,

It is required to get the absolute path of the current directory where my class is residing. This has to happen during runtime inside application server.

Following solutions in the internet were not useful for me.
1)
URL classFileDir = new TestAnything().getClass().getResource("./");
2)
System.out.println(System.getProperty("user.dir"));
3)
File currDir = new File(".");
System.out.println ( "Dir : " + currDir );
System.out.println ( "Dir : " + currDir.getCanonicalPath() );

Any other idea?

Best Regards
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

if you are using servlet class,

try,

ServletContext context = session.getServletContext();
String realContextPath = context.getRealPath(request.getContextPath());
Avatar of inditrozen
inditrozen

ASKER

Thx for reply
I do not have session available in this class.
ASKER CERTIFIED SOLUTION
Avatar of inditrozen
inditrozen

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
no obj
Closed, 500 points refunded.
Vee_Mod
Community Support Moderator