Skip to main content

Relative path on web applications?

2 replies [Last post]
sz_zoli
Offline
Joined: 2008-09-13

Hi!

I have a web application, that has a couple of packages. One of the packages has only wsdl files. From another package, I need to access this wsdl file in order to call a web service. I have the following code line:
url = new URL(baseUrl, "file:../../wsdl/PackagerEndpoint.wsdl");
However this only works in console application, because in console application I know that when I call this code, the relative path is at the class file which belongs to the above mentioned code. But when I try to do the same in a web application, I can't seem to find out where the relative path is at, when I call this line of code. Unfortunately the exception doesn't tell me either. I've tried
System.getProperty("user.dir");
but this didn't really help either.

Can someone tell me where the relative path starts when I call this code in a web application? (I can only get it to work with absolute path now)

Thank you in advance!

Zoli

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jpedwardsdotcom
Offline
Joined: 2008-09-14

If the file you're trying to open is bundled in your web app, and the code that needs to access the file is executed in a servlet or JSP, you could try starting with getServletContext().getRealPath("somefile"). That should point you in the right direction.

If your wsf file is packaged in a JAR that's in the runtime classpath, you could try someClass.getResourceAsStream("somefile"). This puts the job of finding the file on the ClassLoader.

sz_zoli
Offline
Joined: 2008-09-13

Thank you for your answer!

Unfortunately I can't do it the way you said. I'm not using a servlet or a JSP, only a web service. However there is a package in this very same project, which has a wsdl file, and I can't find it using relative path in my web service web application.
In a normal java application it works, however if I try this same thing on web app, it doesn't. And here is the part I don't understand about it:
If I write ../../wsdl/somefile.txt in the normal java application (and let's say I mistyped the address), then the exception tells me exactly where it's trying to look (with full path). But if I do this in a web app, then it just says: "unable to find file at: ../../wsdl/somefile.txt", and it doesn't even give me the full path it's trying to find the file at.