Using Apache CXF to generate code from a WSDL file

Source: Internet
Author: User
Tags wsdl



1, to the official website to download, I use is Apache-cxf-2.5.10.zip



2. Decompression






3. Enter the bin directory of Apache CXF via the command line, as my directory is D:\BIS\axis2\apache-cxf-2.7.10\bin



(This directory is the directory where Wsdl2java.bat is located (if not, the full path where the. bat is written))






4. Enter the command:



Wsdl2java.bat-p com.oscar999-client-encoding utf-8-noaddressbinding wsdl file



Description



Wsdl2java usage:
Wsdl2java-p com-d Src-all aa.wsdl
-p Specifies the namespace of its WSDL, which is the package name to generate code for:
-d Specifies the directory where the code is to be generated
-client generate the code for the Client test Web service (-encoding utf-8 generate Chinese for utf-8 encoding)
-server The build server starts the code for the Web service
-impl Generating the implementation code for a Web service
-ant Generating Build.xml files
-all generates all start endpoint codes: Types,service Proxy,,service interface, server mainline, client mainline, implementation object, and an an T build.xml file.



5. If you are testing in eclipse, you can create a new Java project, copy all the jars under Cxf Lib into the project's Lib path, and put it into the build path.



The resulting Java files are then copied into SRC to invoke the test.



Problems you may encounter:



(a),

Caused by:
org.xml.sax.SAXParseException;
systemId: jar: file: / D: /apache-cxf-2.7.11/apache-cxf-2.7.11/lib/jaxb-xjc2.2.6.jar! / com / sun / tools / xjc / reader / xmlschema / bindinfo /binding.xsd;
lineNumber: 52; columnNumber: 88; schema_reference:
Due to the limitation set by the accessExternalSchema attribute, ‘file’ access is not allowed, so the scheme document ‘xjc.xsd’ cannot be read.
After looking at Baidu on the Internet, I saw the solution given by the Great God and immediately understood.
1. First analyze the cause of the error:
The version of jdk and jre I use is 1.8, and the version of cxf used is apache-cxf-2.7.11. The online god says that this is due to a bug in jdk1.8. Specific details https://bugs.openjdk.java.net / browse / JDK-8020999;
2. Solution:
Under the installation path of jdk, mine is C: \ Java \ jdk1.8.0_65 \ jre \ lib, add a property file jaxp.properties, and write the following content javax.xml.accessExternalSchema = all

(2) About JAXBElement <String> in the client code generated by cxf
    When using cxf or x-fire for webservice development, when generating client code from a wsdl file, if the attribute type is String, JAXBElement <String> type may appear.
    Why the webservice client does not use String directly, but uses JAXBElement <String> type, there is naturally a reason, because the server-side wsdl file has the attribute nillable = "true".

Solution: Use wsdl2java.bat -b "1.txt" -client -d E: / tmp -frontend jaxws21 wsdl file to generate normal pojo class

The content of "1.txt" is as follows:

<jaxb: bindings version = "2.1"
xmlns: jaxb = "http://java.sun.com/xml/ns/jaxb"
xmlns: xjc = "http://java.sun.com/xml/ns/jaxb/xjc"
xmlns: xs = "http://www.w3.org/2001/XMLSchema">
   <jaxb: globalBindings generateElementProperty = "false" />
</ jaxb: bindings>
 

Use Apache CXF to generate code based on wsdl file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.