使用 Eclipse 和 Java SE 6 创建独立 Web Services 应用程序,第 2 部分: Web 服务客户端应用程序
2010-02-02 00:00:00 来源:WEB开发网完成时,可以通过在 Eclipse console 视图中终止 Web 服务来停止它。
使用脚本
为了脱离 Eclipse 运行,可以修改 wsClientExample 的 build.xml,使它在单独的 shell 窗口中启动服务器和客户端应用程序:
双击 build.xml 文件,在 Ant 编辑器中编辑它。
修改该文件,如清单 3 所示。
清单 3. 修改后的 build.xml 文件
<project default="runClient">
<!-- =================================
target: wsimport
================================= -->
<target name="wsimport" description="-->
Read the WSDL and generate the required artifacts">
<exec executable="${java.home}/../bin/wsimport">
<arg line="-keep -s ./src -p com.myfirst.wsClient -d ./bin
http://localhost:8080/wsServerExample?wsdl"/>
</exec>
</target>
<!-- =================================
target: runServer
================================= -->
<target name="runServer" description="-->
Runs the Web service server from a terminal">
<echo>
Running the following command from the terminal to run the server:
${java.home}/bin/java -cp "${basedir}/../wsServerExample/bin"
com.myfirst.wsServer.RunService
</echo>
<exec dir="${java.home}/bin/" executable="cmd" spawn="true"
os="Windows XP" description="runs on XP">
<arg line="start cmd /K start cmd /K" />
<arg line='${java.home}/bin/java -cp
"${basedir}/../wsServerExample/bin"
com.myfirst.wsServer.RunService' />
</exec>
<exec executable="xterm" spawn="true" os="Linux"
description="Runs on Linux">
<arg line="-e ${java.home}/bin/java -cp
'${basedir}/../wsServerExample/bin'
com.myfirst.wsServer.RunService"/>
</exec>
</target>
<!-- =================================
target: pause
================================= -->
<target name="pause" depends="runServer" description="-->
Pauses briefly while the server starts">
<sleep seconds="5"/>
</target>
<!-- =================================
target: runClient
================================= -->
<target name="runClient" depends="pause" description="-->
Runs a Web service client from a terminal">
<echo>
Running the following command from the terminal to run the client:
${java.home}/bin/java -cp "${basedir}/bin" com.myfirst.wsClient.SayHelloClient
</echo>
<exec dir="${java.home}/bin/" executable="cmd" spawn="true"
os="Windows XP" description="Runs on XP">
<arg line="start cmd /K start cmd /K" />
<arg line='${java.home}/bin/java -cp "${basedir}/bin"
com.myfirst.wsClient.SayHelloClient' />
</exec>
<exec executable="xterm" spawn="true" os="Linux"
description="Runs on Linux">
<arg line="-hold -e ${java.home}/bin/java -cp '${basedir}/bin'
com.myfirst.wsClient.SayHelloClient" />
</exec>
</target>
</project>
更多精彩
赞助商链接