JAX-WS =安装Apache CXF时,它“窃取”默认JDK JAX-WS实现,如何解决? [英] JAX-WS = When Apache CXF is installed it "steals" default JDK JAX-WS implementation, how to solve?
问题描述
我有一个奇怪的问题。
-
使用wsimport我从WSDL生成als JAX-WS代码(专用eclipse java项目)。这在JDK6中工作正常,没有任何外部依赖(在Eclipse中运行)
Using wsimport I generated als JAX-WS Code from a WSDL (in a dedicated eclipse java project). This works fine in JDK6 without any external dependencies (running in Eclipse)
我有第二个项目,我曾经使用过Apache CXF。如果我将1.)中描述的代码复制到这个项目中,那么JDK突然不会执行JAX-WS的东西(我生成的文件),而是Apache CXF。
I have second project where I once used Apache CXF. If I copy the Code described in 1.) into this project, suddenly not the JDK executes the JAX-WS stuff (files I generated), but rather Apache CXF.
如何防止Apache CXF运行JAX-WS的东西。 (问题是,CXF无法运行代码......)。我也完全不明白Apache CXF如何发现这些类。我没有注册它们吗?
How can I prevent Apache CXF "running" the JAX-WS stuff. (Problem is, CXF Fails to run the code...). I also completely do not understand how Apache CXF discovers these classes. I did not register them anywere?
非常感谢你!
Markus
Thank you very much! Markus
推荐答案
Apache CXF( cxf-rt-frontend-jaxws - * .jar
确切地说)将自己注册为JVM中的JAX-WS提供程序。在上述JAR中,有一个名为: /META-INF/services/javax.xml.ws.spi.Provider
的文件,其中包含以下内容:
Apache CXF (cxf-rt-frontend-jaxws-*.jar
to be precise) registers itself as a JAX-WS provider in the JVM. Inside the aforementioned JAR there is a file named: /META-INF/services/javax.xml.ws.spi.Provider
with the following contents:
org.apache.cxf.jaxws.spi.ProviderImpl
如果您现在查看 javax.xml.ws.spi.FactoryFinder #find
方法,您将发现JDK在CLASSPATH中搜索是否存在 javax.xml.ws.spi.Provider
文件,如果不可用,则退回到默认的Sun实施。所以你有两种方法可以强制回退:
If you now look at javax.xml.ws.spi.FactoryFinder#find
method you will discover that JDK searches the CLASSPATH for the presence of javax.xml.ws.spi.Provider
file and falls back to default Sun implementation if not available. So you have two options to force fallback:
-
删除
cxf-rt-frontend-jaxws- * .jar
来自CLASSPATH
either remove
cxf-rt-frontend-jaxws-*.jar
from CLASSPATH
或覆盖 javax.xml.ws.spi.Provider
CXF提供的文件指向后备位置
or override javax.xml.ws.spi.Provider
file provided by CXF to point to fallback location
第二个选项实际上更容易一些。只需创建:
The second option is actually a bit easier. Simply create:
/src/main/resources/META-INF/services/javax.xml.ws.spi.Provider
文件(假设您使用的是Maven),内容如下:
file (assuming you are using Maven) with the following contents:
org.apache.cxf.jaxws.spi.ProviderImpl
就是这样,用 javax.xml.ws.Endpoint#publish
测试。
这篇关于JAX-WS =安装Apache CXF时,它“窃取”默认JDK JAX-WS实现,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!