【问题标题】:CXF Web Service Client generation in Maven failedMaven 中的 CXF Web 服务客户端生成失败
【发布时间】:2015-05-26 15:16:00
【问题描述】:

这是我第一次使用 Maven,我正在尝试从 WSDL 生成客户端。 我创建了一个 Maven 项目并从一个类似的项目中下载了一个 pom.xml 文件,然后我运行 mvn assembly:assembly 命令 build 来生成存根,但编译不起作用并产生错误。

这是我的 pom.xml 文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.logicsector</groupId>
  <artifactId>weather-client</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>SOAP weather client</name>

<dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.2</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>weather-client</finalName>
        <plugins>
            <!-- Generate Java classes from WSDL during build -->
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/wsdl/weather.wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Add generated sources - avoids having to copy generated sources to build location -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}/target/generated/src/main/java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Build the JAR with dependencies -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
        <!-- Build with Java 1.5 -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

这是我得到的错误

[INFO] 正在扫描项目... [WARNING] [WARNING] 一些问题 在构建有效模型时遇到了 com.logicsector:weather-client:jar:0.0.1-SNAPSHOT [警告] 'build.plugins.plugin.version' 为 org.codehaus.mojo:build-helper-maven-plugin 丢失。 @ 第 61 行, 第 21 列 [WARNING] [WARNING] 强烈建议修复这些 问题,因为它们威胁到您构建的稳定性。 [警告] [警告] 出于这个原因,未来的 Maven 版本可能不再 支持建设此类畸形项目。 [警告] [信息]
[信息] -------------------------------------------------- ---------------------- [INFO] 构建 SOAP 天气客户端 0.0.1-SNAPSHOT [INFO] -------------------------------------------------- ---------------------- [INFO] [INFO] >>> maven-assembly-plugin:2.2-beta-5:assembly (default-cli)@weather-client >>> [INFO] [INFO] --- cxf-codegen-plugin:2.1.2:wsdl2java (generate-sources) @ weather-client --- 2015 年 3 月 23 日下午 3:11:05 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO:正在刷新 org.apache.cxf.bus.spring.BusApplicationContext@466d9e6c:显示名称 [org.apache.cxf.bus.spring.BusApplicationContext@466d9e6c];启动 日期 [2015 年 3 月 23 日星期一 15:11:05 GMT+01:00];上下文层次的根 2015 年 3 月 23 日下午 3:11:05 org.apache.cxf.bus.spring.BusApplicationContext getConfigResources 信息:未检测到 cxf.xml 配置文件,依赖于默认值。 2015 年 3 月 23 日下午 3:11:05 org.springframework.context.support.AbstractApplicationContext 获得FreshBeanFactory INFO:应用上下文的Bean工厂 [org.apache.cxf.bus.spring.BusApplicationContext@466d9e6c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@7f85e8ac 2015 年 3 月 23 日下午 3:11:06 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization 信息:Bean 'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor' 不符合条件 被所有 BeanPostProcessors 处理(例如:不 符合自动代理条件)2015 年 3 月 23 日下午 3:11:06 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization 信息:Bean 'org.apache.cxf.bus.spring.BusExtensionPostProcessor' 不符合条件 被所有 BeanPostProcessors 处理(例如:不 符合自动代理条件)2015 年 3 月 23 日下午 3:11:06 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO:预实例化单例 org.springframework.beans.factory.support.DefaultListableBeanFactory@7f85e8ac: 定义 bean [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org .apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org .apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org .apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager ,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.jaxws.context.WebServiceContextResourceResolver,org.apache.cxf.jaxw s.context.WebServiceContextImpl,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.binding。 xml.XMLBindingFactory、org.apache.cxf.ws.addressing.policy.AddressingAssertionBuilder、org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider、org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder、org.apache。 cxf.transport.http.policy.HTTPClientAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory] ; 工厂层次结构的根 mars 23, 2015 3:11:10 PM org.springframework.context.support.AbstractApplicationContext doClose 信息:关闭 org.apache.cxf.bus.spring.BusApplicationContext@466d9e6c:显示名称 [org.apache.cxf.bus.spring.BusApplicationContext@466d9e6c];启动 日期 [2015 年 3 月 23 日星期一 15:11:05 GMT+01:00];上下文层次的根 2015 年 3 月 23 日下午 3:11:10 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons INFO: 销毁单例 org.springframework.beans.factory.support.DefaultListableBeanFactory@7f85e8ac: 定义 bean [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org .apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org .apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org .apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager ,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.jaxws.context.WebServiceContextResourceResolver,org.apache.cxf.jaxw s.context.WebServiceContextImpl,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.binding。 xml.XMLBindingFactory、org.apache.cxf.ws.addressing.policy.AddressingAssertionBuilder、org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider、org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder、org.apache。 cxf.transport.http.policy.HTTPClientAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory] ; 工厂层次结构的根 [INFO] -------------------------------------------------- ---------------------- [信息] 构建失败 [信息] -------------------------------------------------- ---------------------- [INFO] 总时间:9.122s [INFO] 完成时间:Mon Mar 23 15:11:10 GMT+01:00 2015 [INFO] 最终内存:21M/311M [INFO] -------------------------------------------------- ---------------------- [错误] 未能执行目标 org.apache.cxf:cxf-codegen-plugin:2.1.2:wsdl2java (generate-sources) 关于项目天气客户端:执行生成目标的来源 org.apache.cxf:cxf-codegen-plugin:2.1.2:wsdl2java 失败:非法 索引 2 处不透明部分的字符: D:\gireveWorkSpace\weather-client/src/main/wsdl/weather.wsdl -> [帮助 1] [ERROR] [ERROR] 要查看错误的完整堆栈跟踪,请重新运行 带有 -e 开关的 Maven。 [错误] 使用 -X 开关重新运行 Maven 启用完整的调试日志记录。 [错误] [错误] 有关更多信息 错误和可能的解决方案,请阅读以下文章: [错误] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

我正在使用 Eclipse Juno 并成功配置了 Maven,请您帮我找到解决方案。

【问题讨论】:

  • 你为什么要使用相当老的 CXF 版本和 JDK 1.5 版本,而你的 mvn 是使用 jdk 1.5
  • 嗨 Karthik,我使用的是 Eclipse Juno,它与最新版本的 Maven 不兼容,所以我使用的是 Maven 1.4,这个版本使用旧的 CXF,这是我的想法,但我是新手,所以我将不胜感激!
  • Eclipse Juno 支持 Maven 3,
  • 我尝试安装 Maven 1.5 但出现错误然后我搜索并找到了这个stackoverflow.com/questions/25454374/…
  • 它不是支持 maven 任务的插件版本的 maven 版本。该插件名为m2e,

标签: web-services maven jakarta-ee wsdl cxf


【解决方案1】:

你可以在 pom.xml 下面使用

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.logicsector</groupId>
  <artifactId>weather-client</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>SOAP weather client</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cxf.version>2.7.5</cxf.version>
        <slfj.version>1.7.5</slfj.version>
        <jdk.version>1.6</jdk.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slfj.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${slfj.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>log4j-over-slf4j</artifactId>
            <version>${slfj.version}</version>
        </dependency>
    </dependencies>

    <build>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.cxf</groupId>
                                        <artifactId>cxf-codegen-plugin</artifactId>
                                        <versionRange>[2.7,)</versionRange>
                                        <goals>
                                            <goal>wsdl2java</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/weather.wsdl</wsdl>
                                    <wsdlLocation>classpath:wsdl/ServiceManagement.wsdl</wsdlLocation>
                                    <extraargs>
                                        <extraarg>-verbose</extraarg>
                                        <extraarg>-client</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Maven compiler -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

您可以根据需求和属性标签中的 jdk 版本更改 cxf 版本。虽然您说的版本是 maven eclipse plugin (m2e),但是 eclipse 支持 maven 版本 3,并且更多依赖项独立于 maven 版本。

另外一点值得注意的目录结构,配置中的wsdl目录在classpath之外。默认情况下,在 maven 中,src/main/java,src/main/resources 是类路径(在打包过程中也会考虑这一点)。因此相应地修改了您的 cxf 插件配置

【讨论】:

  • 感谢 Karthik,当我开始使用 Maven 时,我会考虑这些建议,但现在我什至无法安装它!我安装了 Maven 3,但我无法安装最近的插件! Maven Market 报此错误marketplace.eclipse.org/content/error/report/2241251
  • 你不需要安装最新的m2e插件,这些插件可能与旧版本不兼容。使用 m2e 插件版本 1.4 本身。
  • 我一开始就是这么做的!但现在我正在下载 Eclipse Luna 来使用它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-23
  • 1970-01-01
  • 1970-01-01
  • 2011-04-13
  • 1970-01-01
  • 2011-04-05
相关资源
最近更新 更多