Hi,
Just a post concerning the generation of JAVA webservice client for CXF and AXIS web services via an ANT script.
More information on sites on proxies creation:
http://cxf.apache.org/docs/wsdl-to-java.html
http://axis.apache.org/axis/java/ant/axis-wsdl2java.html
- First, download the CXF and AXIS SDK librairies:
C:\SDK\axis2-1.7.7
C:\SDK\cfx-3.0.3
C:\SDK\jdk1.7.0_17
- Create a specific folder for the generated proxies sources (for example, WSProxyGenerator\src_generated)
- References all needed libairies (JAR) in your project (for example lib/*.jar)
- Create a properties file for the ANT script build.properties:
1
cxf.home=C\:/SDK/cfx-3.0.3
2
axis.home=C\:/SDK/axis2-1.7.7
- Create a ANT script file build.xml containing the ANT targets create_proxy depending of init_proxy, create_proxy_cxf and create_proxy_axis targets:
01
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
02
<
project
name
=
"ProxiesGenerator"
default
=
"create_proxy"
basedir
=
"."
>
03
<
property
file
=
"build.properties"
/>
04
05
<
target
name
=
"create_proxy"
depends
=
"init_proxy,create_proxy_cxf,create_proxy_axis"
>
06
</
target
>
07
08
<
target
name
=
"init_proxy"
>
09
<
fail
unless
=
"cxf.home"
message
=
"Apache CXF home (cxf.home) not set"
/>
10
<
path
id
=
"cxf.classpath"
>
11
<
fileset
dir
=
"${cxf.home}/lib"
>
12
<
include
name
=
"*.jar"
/>
13
</
fileset
>
14
</
path
>
15
16
<
fail
unless
=
"axis.home"
message
=
"Apache AXIS home (axis.home) not set"
/>
17
18
<
path
id
=
"axis.classpath"
>
19
<
fileset
dir
=
"${axis.home}/lib"
>
20
<
include
name
=
"*.jar"
/>
21
</
fileset
>
22
<
fileset
dir
=
"${basedir}/lib"
>
23
<
include
name
=
"*.jar"
/>
24
</
fileset
>
25
</
path
>
26
27
<
delete
includeemptydirs
=
"true"
>
28
<
fileset
dir
=
"${basedir}/src_generated"
>
29
<
include
name
=
"**/*.java"
/>
30
</
fileset
>
31
</
delete
>
32
<
mkdir
dir
=
"${basedir}/src_generated"
/>
33
</
target
>
34
35
<
target
name
=
"create_proxy_cxf"
>
36
</
target
>
37
38
<
target
name
=
"create_proxy_axis"
>
39
</
target
>
40
</
project
>
CXF proxy generation
- Create a file containing the URLs of CXF web services wsdllist_cxf.txt:
- Create a file for the binding-name simple-binding.xjb
1
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
2
<
jaxb:bindings
xmlns:jaxb
=
"http://java.sun.com/xml/ns/jaxb"
3
jaxb:version
=
"2.0"
xmlns:xjc
=
"http://java.sun.com/xml/ns/jaxb/xjc"
4
jaxb:extensionBindingPrefixes
=
"xjc"
>
5
<
jaxb:globalBindings
>
6
<
xjc:simple
/>
7
<
xjc:serializable
uid
=
"1397139757393"
/>
8
</
jaxb:globalBindings
>
9
</
jaxb:bindings
>
- Create in the build.xml file the CXF target:
01
<
target
name
=
"create_proxy_cxf"
>
02
<
java
classname
=
"org.apache.cxf.tools.wsdlto.WSDLToJava"
fork
=
"true"
>
03
<
arg
value
=
"-autoNameResolution"
/>
04
<
arg
value
=
"-verbose"
/>
05
<
arg
value
=
"-fe"
/>
06
<
arg
value
=
"jaxws21"
/>
07
<
arg
value
=
"-encoding"
/>
08
<
arg
value
=
"Cp1252"
/>
09
<
arg
value
=
"-d"
/>
10
<
arg
value
=
"${basedir}/src_generated"
/>
11
<
arg
value
=
"-b"
/>
12
<
arg
value
=
"simple-binding.xjb"
/>
13
<
arg
value
=
"-wsdlList"
/>
14
<
arg
value
=
"wsdllist_cxf.txt"
/>
15
<
classpath
>
16
<
path
refid
=
"cxf.classpath"
/>
17
</
classpath
>
18
</
java
>
19
</
target
>
AXIS proxy generation
- Create in the build.xml file the CXF target:
01
<
target
name
=
"create_proxy_axis"
>
02
<
java
classname
=
"org.apache.axis.wsdl.WSDL2Java"
fork
=
"true"
>
03
<
arg
value
=
"--verbose"
/>
04
<
arg
value
=
"--Debug"
/>
05
<
arg
value
=
"--output"
/>
06
<
arg
value
=
"${basedir}/src_generated"
/>
07
<
arg
value
=
"-u"
/>
08
<
arg
value
=
"https://myserver2.java.lu/MyWebServices/services/MyWebService?wsdl"
/>
09
<
classpath
>
10
<
path
refid
=
"axis.classpath"
/>
11
</
classpath
>
12
</
java
>
13
</
target
>
build.xml
01 | <? xml version = "1.0" encoding = "UTF-8" ?> |
02 | < project name = "ProxiesGenerator" default = "create_proxy" basedir = "." > |
03 | < property file = "build.properties" /> |
04 |
05 | < target name = "create_proxy" depends = "init_proxy,create_proxy_cxf,create_proxy_axis" > |
06 | </ target > |
07 | |
08 | < target name = "init_proxy" > |
09 | < fail unless = "cxf.home" message = "Apache CXF home (cxf.home) not set" /> |
10 | < path id = "cxf.classpath" > |
11 | < fileset dir = "${cxf.home}/lib" > |
12 | < include name = "*.jar" /> |
13 | </ fileset > |
14 | </ path > |
15 |
16 | < fail unless = "axis.home" message = "Apache AXIS home (axis.home) not set" /> |
17 |
18 | < path id = "axis.classpath" > |
19 | < fileset dir = "${axis.home}/lib" > |
20 | < include name = "*.jar" /> |
21 | </ fileset > |
22 | < fileset dir = "${basedir}/lib" > |
23 | < include name = "*.jar" /> |
24 | </ fileset > |
25 | </ path > |
26 |
27 | < delete includeemptydirs = "true" > |
28 | < fileset dir = "${basedir}/src_generated" > |
29 | < include name = "**/*.java" /> |
30 | </ fileset > |
31 | </ delete > |
32 | < mkdir dir = "${basedir}/src_generated" /> |
33 | </ target > |
34 |
35 | < target name = "create_proxy_cxf" > |
36 | < java classname = "org.apache.cxf.tools.wsdlto.WSDLToJava" fork = "true" > |
37 | < arg value = "-autoNameResolution" /> |
38 | < arg value = "-verbose" /> |
39 | < arg value = "-fe" /> |
40 | < arg value = "jaxws21" /> |
41 | < arg value = "-encoding" /> |
42 | < arg value = "Cp1252" /> |
43 | < arg value = "-d" /> |
44 | < arg value = "${basedir}/src_generated" /> |
45 | < arg value = "-b" /> |
46 | < arg value = "simple-binding.xjb" /> |
47 | < arg value = "-wsdlList" /> |
48 | < arg value = "wsdllist_cxf.txt" /> |
49 | < classpath > |
50 | < path refid = "cxf.classpath" /> |
51 | </ classpath > |
52 | </ java > |
53 | </ target > |
54 |
55 | < target name = "create_proxy_axis" > |
56 | < java classname = "org.apache.axis.wsdl.WSDL2Java" fork = "true" > |
57 | < arg value = "--verbose" /> |
58 | < arg value = "--Debug" /> |
59 | < arg value = "--output" /> |
60 | < arg value = "${basedir}/src_generated" /> |
61 | < arg value = "-u" /> |
62 | < arg value = "https://myserver2.java.lu/MyWebServices/services/MyWebService?wsdl" /> |
63 | < classpath > |
64 | < path refid = "axis.classpath" /> |
65 | </ classpath > |
66 | </ java > |
67 | </ target > |
68 | </ project > |
Execute the ANT script build.xml, the proxies are generated in the src_generated folder:
01 | Buildfile: C:\Workspaces\WSProxyGenerator\build.xml |
02 | init_proxy: |
03 | create_proxy_cxf: |
04 | Loading FrontEnd jaxws21 ... |
05 | Loading DataBinding jaxb ... |
06 | wsdl2java -autoNameResolution -verbose -fe jaxws21 -encoding Cp1252 -d C:\Workspaces\WSProxyGenerator/src_generated -b simple-binding.xjb -wsdlList wsdllist_cxf.txt |
07 | wsdl2java - Apache CXF 3.0.3 |
08 | create_proxy_axis: |
09 | Parsing XML file: https://myserver2.java.lu/MyWebServices/services/MyWebService?wsdl |
10 | Symbol Table |
11 | ----------------------- |
12 | org.apache.axis.wsdl.symbolTable.DefinedType |
13 | ... |
14 | ----------------------- |
15 | Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebService.java |
16 | Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebServiceSoapBindingStub.java |
17 | Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebServiceService.java |
18 | Generating C:\Workspaces\WSProxyGenerator/src_generated\com\myjava\lu\myservice\webservice\services\myserviceWebServiceServiceLocator.java |
19 | create_proxy: |
20 | BUILD SUCCESSFUL |
21 | Total time: 11 seconds |
Best regards,
Huseyin