在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.

你可能感兴趣的:(java,eclipse,jdk,maven,wordpress)