开发者

wsimport generates faulty code

I use wsimport to generate my java stub files. For this, I use an ant build file in Eclipse:

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath>
        <fileset dir="../lib">
            <include name="jaxws-tools.jar" />
        </fileset>
    </classpath>
</taskdef>

<target name="generate">
    <wsimport wsdl="../wsdl/Knowledgebase.wsdl"
              destdir="../bin"
              sourcedestdir="../gen"
              keep="true"
              xendorsed="true">
    </wsimport>
</target>

The task runs without any errors. It creates different java-files, also Knowledgebase.java and KnowledgebasePort.java. In der Knowledgebase.java, there are these constructors:

public Knowledgebase(WebServiceFeature... features) {
    super(__getWsdlLocation()开发者_运维问答, KNOWLEDGEBASE_QNAME, features);
}

For them I get an error "The constructor Service(...) is undefined". I imported the current jax-ws jar files. Is my generation process broken, do I use the wrong jars or where is the error?


The Service object is provided by the Java EE SDK. It added a new constructor between Java EE 5 and Java EE 6. It would seem the wsimport you're using is from a Java EE 6 JDK and the compiler is using a Java EE 5 SDK?


If we using for example java 1.6.0_27 and Metro 2.2 we need to ENDORSE the webservices-api.jar.

  1. We have to put this jar into folder java-install-dir\jre\lib\endorsed\
  2. In case of using Eclipse, we have to ensure that we are using the correct JRE from the directory java-install-dir. This is done in Window->Preferences->Java->Installed JREs->Add.

Now the error "The constructor Service(...) is undefined" should disappear.


You can set xendorsed="true" and xnocompile="false" and let ant compile your generated java files and it worked for me

<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
        <classpath>
            <fileset dir="${ext.myproject.path}/lib">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${platformhome}/resources/ant/lib">
                <include name="*.jar"/>
            </fileset>
        </classpath>    
</taskdef>

<macrodef name="myproject_before_compile_core">
        <sequential>
            <mkdir dir="${ext.myproject.path}/gensrc"/>
            <mkdir dir="${ext.myproject.path}/classes"/>
            <echo message="Generating WS stubs for Simulate BOM Service"/>
            <wsimport wsdl="${ext.myproject.path}/resources/wsdl/service.wsdl" package="com.xx.energy.yy.xyz.ws.stubs.service" xnocompile="false" destdir="${ext.myproject.path}/classes" sourcedestdir="${ext.myproject.path}/gensrc" keep="true" wsdlLocation="${ext.myproject.path}/resources/wsdl" xendorsed="true">
                <produces dir="${ext.myproject.path}/gensrc/com/xx/energy/yy/xyz/ws/stubs/service">
                    <include name="*.java"/>
                </produces>
                <depends file="${ext.myproject.path}/resources/wsdl/service.wsdl"/>
            </wsimport>
        </sequential>
    </macrodef>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜