使用CXF wsdl2java将jar中的wsdl捆绑在一起 [英] Bundling wsdl in jar with CXF wsdl2java

查看:106
本文介绍了使用CXF wsdl2java将jar中的wsdl捆绑在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个实现,它将使用我从供应商处获得的wsdl。我们的项目在Spring和CXF上运行,我想创建一个允许我访问这个供应商的wsdl服务的jar,但是我遇到了类路径问题。

I'm working on an implementation that will use a wsdl that I have gotten from a vendor. Our project is running on Spring and CXF, and I'd like to create a jar that will allow me to access this vendor's wsdl services, but I'm running into classpath issues.

使用CXF的wsdl2java我能够生成如下代码:

Using CXF's wsdl2java I am able to generate code that acts like this:

WSDL_LOCATION = new URL("file:SomeService.wsdl");

该服务要求wsdl在类路径中,但我想将它捆绑在jar中这样它就可以作为一个独立的jar分发。使用wsdl2java工具,我能够将URL实例化中的字符串指定为我想要的任何内容。但是,我没有在jar中找到自定义字符串和wsdl文件位置的组合。

The service requires the wsdl to be in the classpath, but I would like to bundle it in the jar so that it is distributable as a stand-alone jar. Using the wsdl2java tool, I am able to specify the string in the URL instantiation to whatever I would like. However, I have not found a combination of a custom string and wsdl file location inside the jar that works.

我想要的唯一方法是按照我的意愿工作将wsdl文件放在SomeService.class所在的文件夹中,并使用以下行:

The only way I have gotten this to work as I want is to put the wsdl file in the same folder that the SomeService.class is and use the following line:

WSDL_LOCATION = TrackService.class.getResource("TrackService_v4.wsdl");

但是,我不得不手动编辑java代码并自行编译。这是不可取的,因为我们最终希望将此进程作为maven构建的一部分,并让wsdl2java自动生成和编译。

However, this has the downside of me having to manually edit the java code and compile it myself. This is undesirable because we would eventually like to make this process part of our maven build and have wsdl2java do the generation and compilation by itself automatically.

我对wsdl没问题在jar中的任何地方,但我不知道要传递给wsdl2java以使其引用jar中的文件。

I am OK with the wsdl being anywhere in the jar, but I don't know what to pass in to wsdl2java to have it reference a file inside the jar.

有没有人有这方面的建议或经验?

Does anyone have any suggestions or experience doing this?

推荐答案

您需要按如下方式指定classpath wsdl位置以生成使用ClassLoader将此wsdl加载为类路径资源的存根:

You need to specify the classpath wsdl location as follows to generate the stubs that uses ClassLoader to load this wsdl as classpath resource:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>2.4.3</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-bindings-soap</artifactId>
            <version>2.4.3</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
                <sourceRoot>${project.build.directory}/generated-sources/cxf
                </sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/yourWSDL.wsdl</wsdl>
                        <extraargs>
                            <extraarg>**-wsdlLocation**</extraarg>
                            <extraarg>**classpath:yourWSDL.wsdl**</extraarg>
                        </extraargs>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这篇关于使用CXF wsdl2java将jar中的wsdl捆绑在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆