Reputation: 24507
I have a web project and a source project.
In the web project I have a folder called xsd
which I would like to access in my java files from the source project.
From a servlet or jsp I can access the xsd using
getServletContext().getRealPath("/xsd")
However, from the source project where I have no servletcontext, I don't know who to get hold of the xsd
folder in the web project. I cannot use absolute path as this is unknown when the project is deployed to our production servers.
When I use File
in java I get
new File(".")
prints C:\SDP75\runtimes\base_v61\profiles\was61profile1\
which does not contain my xsd folder and web project
How can I easily do this?
Upvotes: 0
Views: 467
Reputation: 35068
Could you not put the xsd on the classpath and then do
Thread.currentThread().getContextClassLoader().getResourceAsStream("xsd/A.xsd");
It wouldn't give you a File
but would that be sufficient?
EDIT: Removed leading /
as that's only applicable to Class.getResource()
not Classloader.getResource()
.
Upvotes: 2