开发者

Java - Apache CXF Load WSDL From Jar

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 p开发者_如何转开发ath 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜