I want to find context path of my web Application in normal Java class.If I find I can specify paths like this /Rod1/thermalMap.exe
wherever I need.
I know, How to find in servlet
using the following code
getServletContext().getRealPath("");
My webApps folder in the following way.
You can get the absolute path to to your webApp/WEB-INF/classes
directory as below:
URL resource = getClass().getResource("/");
String path = resource.getPath();
This will return you an absolute path like this:
/C:/SERVERS/x/y/x/yourApp/WEB-INF/classes
And from this you can get the path to the yourApp
directory:
path = path.replace("WEB-INF/classes/", "");
which you can use to specify paths like /Rod1/thermalMap.exe
, by appending to this path
.
Have you try this?
String path = new File(".").getCanonicalPath();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With