这是我对Maven的首次使用,我正在尝试从WSDL生成客户端。我创建了一个Maven项目,并从类似的项目中下载了pom.xml文件,然后运行了mvn assembly:assembly命令来生成存根,但是编译不起作用,并且会产生错误。
这是我的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>
这是我得到的错误
[信息]扫描项目... [警告] [警告]为com.logicsector:weather-client:jar:0.0.1-SNAPSHOT构建有效模型时遇到了一些问题[警告]'build.plugins.plugin。缺少org.codehaus.mojo的版本号:build-helper-maven-plugin。@第61行,第21列[警告] [警告]强烈建议解决这些问题,因为它们会威胁到您的构建的稳定性。[警告] [警告]因此,将来的Maven版本可能不再支持构建此类格式错误的项目。[警告] [信息]
[INFO] ----------------------------------------------- ------------------------- [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 --- Mars 23,2015 3:11:05 PM 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];上下文层次结构的根mars 23,2015 3:11:05 PM org.apache.cxf.bus.spring.BusApplicationContext getConfigResources信息:没有cxf。检测到xml配置文件,取决于默认值。2015年3月23日3:11:05 org.springframework.context.support.AbstractApplicationContext getFreshBeanFactory INFO:应用程序上下文的Bean工厂[org.apache.cxf.bus.spring.BusApplicationContext@466d9e6c]:org.springframework.beans.factory .support.DefaultListableBeanFactory @ 7f85e8ac mars 23,2015 3:11:06 PM org.springframework.context.support.AbstractApplicationContext $ BeanPostProcessorChecker postProcessAfterInitialization INFO:Bean'org.apache.cxf.bus.spring.Jsr250BeanPostProcessor'不符合获取条件的条件由所有BeanPostProcessor提供(例如:不符合自动代理资格)Mars 23,2015 3:11:06 PM org.springframework.context.support.AbstractApplicationContext $ BeanPostProcessorChecker postProcessAfterInitialization信息:Bean'org.apache.cxf.bus.spring。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 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];上下文层次结构的根Mars 23,2015 3:11:10 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons信息:NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory]; 工厂层次结构的根[INFO] ------------------------------------------- ----------------------------- [INFO]内置故障[INFO] ------------- -------------------------------------------------- --------- [INFO]总时间:9.122s [INFO]完成时间:2015年3月23日星期一15:11:10 GMT + 01:00 [INFO]最终内存:21M / 311M [INFO]- -------------------------------------------------- --------------------- [错误]无法执行目标org.apache.cxf:cxf-codegen-plugin:2.1.2:wsdl2java(生成源)在项目weather-client上:执行目标org.apache.cxf:cxf-codegen-plugin:2.1.2:wsdl2java的生成源失败:索引2处不透明部分中的非法字符:D:\ gireveWorkSpace \ weather-client / src /main/wsdl/weather.wsdl-> [帮助1] [错误] [错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。[错误]使用-X开关重新运行Maven以启用完整的调试日志记录。[错误] [错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:[错误] [帮助1]http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
我正在使用Eclipse Juno,并且已经成功配置了Maven,请您帮我找到解决方案。
好吧,您可以在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插件(m2e),但是eclipse支持maven版本3,并且更多依赖项独立于maven版本。
值得注意的目录结构的另一点是,配置中的wsdl目录位于类路径之外。默认情况下src/main/java
,在Mavensrc/main/resources
中,classpath是类路径(打包时也要考虑)。因此相应地修改了您的cxf插件配置
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句