在eclipse中使用wsimport的maven插件开发WSDL客户端

有空再翻译了。http://itangeek.com/wordpress/?p=143

 

Our project will use maven, and for the external link, we got the interface description in WSDL as the web service. So I think we can easily generate java client, but seems thinks always not so easy.

First I tried the Axis1 and Axis2, but they seems not perfect, especially for "MaxOccurs='0' ", which means the element could be omitted, but in the generated java code, it comes as the mandatory parameters, because it is implemented as the List.

 

Finally we found the JDK tools - "wsimport" could be suitable for our solution (CXF also OK), so I check the maven plugin, but seems the plugin "jaxws-maven-plugin" is not in the active develop model,  I can find limited example of this.

 

The first problem is the parameters, in the official web site, I can only find one parameters "packageName", but I also want to indicate the input WSDL file and directory, and also different mapping rules for different WSDL files. Luckily we have google. Here is the parameters supported by the plugin.

 

http://mojo.codehaus.org/jaxws-maven-plugin/wsimport-mojo.html

 

But another problem come up, when I try to have different execution, it seems only the first one executed, google again, the reason is the plugin has the state recorded, the different execution use the same directory and file name, so after the first one finished, other will get the executed status, and will not be executed again. So the work around is to set different statflag directory for different executions.

 

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>jaxws-maven-plugin</artifactId>
	<executions>
		<execution>
			<id>1</id> 
			<configuration>
				<extension>true</extension>
				<verbose>true</verbose>
				<wsdlDirectory>src/main/java/com/fd/link/</wsdlDirectory>
				<sourceDestDir>src/main/java/</sourceDestDir>
				<wsdlFiles>
					<wsdlFile>linkApple.wsdl</wsdlFile>
				</wsdlFiles>
				<staleFile>src/main/java/com/fd/link/linkApple.asmx.stale</staleFile> 
				<packageName>com.fd.link.linkApple</packageName>
			</configuration>
			<goals>
				<goal>wsimport</goal>
			</goals>
		</execution>
		<execution>
			<id>2</id>
			<configuration>
				<extension>true</extension>
				<verbose>true</verbose>
				<wsdlDirectory>src/main/java/com/fd/link/</wsdlDirectory>
				<sourceDestDir>src/main/java/</sourceDestDir>
				<wsdlFiles>
					<wsdlFile>linkBird.wsdl</wsdlFile>
				</wsdlFiles>
				<staleFile>src/main/java/com/fd/link/linkBird.asmx.stale</staleFile> 
				<packageName>com.fd.link.linkBird</packageName>
			</configuration>
			<goals>
				<goal>wsimport</goal>
			</goals>
		</execution>
	</executions>
</plugin>
 
 
 

 

It seems OK, but we have another problem, according to the official example, it depend on JDK tools. But the console report error, and the directory always indicated to Jre. And it is because the ${java.home} used in maven will refer to the JVM used by eclipse, and by default, it is Jre used by system, so to solve this problem, just configure eclipse.ini, add "-vm c:/jdk/bin/javax.exe" .

OK, maven running with jaxws-maven-plugin, the client generated successfully.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值