Reputation:
I am using Apache CXF to connect to a SOAP API. I've saved the WSDL in my Eclipse project and I want to load this. My project looks like this:
src
gen
resources +
META-INF +
myWSDL.wsdl
I can load the WSDL if I hard code in the path from the root of my drive:
static {
URL url = null;
try {
url = new URL("file:/home/peter/workspace/project/resources/META-INF/myWSDL.wsdl");
System.out.println(url);
} catch (MalformedURLException e) {
//blah
}
}
However, if I try to load the WSDL as a resource it fails:
static {
URL url = null;
try {
url = MyServiceClass.class.getResource("/resource/META-INF/BFExchangeService.wsdl");
System.out.println(url); //prints null
} catch (MalformedURLException e) {
//blah
}
}
How do I load the WSDL from within my project (and, eventually, my .jar)?
Cheers,
Pete
Upvotes: 2
Views: 2268
Reputation: 9110
Class.getResource
loads a file from the classpath, so you're on the right track.
So, store your wsdl somewhere on your classpath, e.g. your source folder, and treat the source folder as the root of the 'filesystem' e.g. getResource("/myWSDL.wsdl")
HTH
Upvotes: 3