java 在提供 Maven 工件的 Wildfly 部署中使用 CXF 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31099208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 18:06:52  来源:igfitidea点击:

Use CXF libraries in Wildfly deployment with Maven artifact provided

javaweb-servicesmavenjax-wswildfly

提问by mr-anderson

Im trying to deploy a project containing an JAX-WS Interface to a wildfly 8.2 server. The project is packed as a war. Within that project I would like to use interceptors.

我正在尝试将包含 JAX-WS 接口的项目部署到 Wildfly 8.2 服务器。这个项目就像一场War。在那个项目中,我想使用拦截器。

import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
public class ReplyToHeaderInInterceptor extends AbstractSoapInterceptor { /*code*/}

I'm using Maven with the "provided" tag, in order to not receiving the following error:

我正在使用带有“provided”标签的 Maven,以免收到以下错误:

Apache CXF library (cxf-rt-bindings-soap-3.1.1.jar) detected in ws endpoint deployment; either provide a proper deployment replacing embedded libraries with container module dependencies or disable the webservices subsystem for the current deployment adding a proper jboss-deployment-structure.xml descriptor to it. The former approach is recommended, as the latter approach causes most of the webservices Java EE and any JBossWS specific functionality to be disabled.

That looks like this:

看起来像这样:

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.1.1</version>
        <scope>provided</scope>
    </dependency>

But if I do so the library cannot be found at runtime:

但是,如果我这样做,则在运行时找不到该库:

Caused by: java.lang.NoClassDefFoundError: org/apache/cxf/binding/soap/interceptor/AbstractSoapInterceptor

I have already tried adding the dependency via the MANIFEST.MF file using maven:

我已经尝试使用 maven 通过 MANIFEST.MF 文件添加依赖项:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                <warName>backend</warName>
               <archive>
                  <manifestEntries>
                     <Dependencies>org.apache.cxf</Dependencies>
                  </manifestEntries>
               </archive>
            </configuration>
        </plugin>

I don't know what to do, any suggestions?

我不知道该怎么办,有什么建议吗?

采纳答案by mr-anderson

It turned out adding a jboss-deployment-structure.xmlfile to WEB-INFfolder with the following content did the trick:

事实证明,将一个jboss-deployment-structure.xml文件添加到WEB-INF包含以下内容的文件夹就可以了:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <deployment>
        <exclusions>
        </exclusions>
        <dependencies>
            <module name="org.apache.cxf" />
            <module name="org.apache.cxf.impl" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>

Eventhough I tried it before with org.apache.cxfonly,I had to add org.apache.cxf.impl

尽管我之前org.apache.cxf只尝试过,但我不得不添加org.apache.cxf.impl

回答by zhrist

The other option is to use your own structure, than the modules(versions) offered in Wildfly server deployment. This is done with jboss-deployment-structure.xml file to WEB-INF with this content:

另一种选择是使用您自己的结构,而不是 Wildfly 服务器部署中提供的模块(版本)。这是通过 jboss-deployment-structure.xml 文件到 WEB-INF 的内容完成的:

  <deployment>
    <exclude-subsystems>
        <subsystem name="webservices" /> 
    </exclude-subsystems>  
  </deployment>

This will disable webservice framework included in Wildfly and use war included libraries(lib jars)

这将禁用 Wildfly 中包含的 webservice 框架并使用包含War的库(lib jars)

This is mentioned in related question/answer: How to access CXF jars from Wildfly (Jboss) for ws endpoints

这在相关问题/答案中提到: How to access CXF jars from Wildfly (Jboss) for ws endpoints