1

嗨,我正在学习 web 服务,因为我正在创建一个示例项目,该项目从给定的 wsdl(wsdl2Java) 生成 java 并将代码生成到 wsdl(java2ws)。wsdl2java 工作正常,但在 java2wsdl 中,我的 ANT 文件中出现如下异常

Buildfile: D:\sarvan\java\webservice\java2wsVSws2java\build.xml
cxfWSDLToJava:
[echo] **********Genarating WSDLToJava***********
cxfJavaToWSDL:
[echo]  ************Genarating JavaToWSDL************* 
[java] JavaToWS Error: org.apache.cxf.tools.common.ToolException: Fail  to load class : D:\sarvan\java\webservice\java2wsVSws2java\build    \genClasses/com/saravana/webservice/services/CalServiceService.class
 compile-all:
[javac] D:\sarvan\java\webservice\java2wsVSws2java\build.xml:54:    warning: 'includeantruntime' was not set, defaulting to     build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 9 source files to D:\sarvan\java\webservice \java2wsVSws2java\build\genClasses
BUILD SUCCESSFUL
Total time: 5 seconds

请问是什么原因造成的,求大神帮忙!!我的蚂蚁:

<target name="cxfJavaToWSDL" depends="cxfWSDLToJava">
<echo> ************Genarating JavaToWSDL************* </echo>
  <java classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true">
  <arg value="-wsdl"/>
      <arg value="-classdir"/>
      <arg value="${classes}"/>
     <arg value="-cp"/>
      <arg value="${classes}/**/CalServiceService.class"/>
       <arg value="-o"/>
     <arg value="${lib.dir}/CalServiceService.wsdl"/>
     <arg value="${classes}/com/saravana/webservice/services/CalServiceService.class"/>
     <classpath>
        <path refid="class.path"/>
         <pathelement location="${classes}/**/*.class"/> 
     </classpath>
  </java>

<target name="cxfWSDLToJava" >
  <echo message="**********Genarating WSDLToJava***********"/>    
  <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
     <arg value="-client"/>
     <arg value="-d"/>
     <arg value="${genCode.dir}"/>
     <!-- <arg value="-b"/>
     <arg value="./async_binding.xml"/> -->
     <arg value="${lib.dir}/CalService.wsdl"/>
     <classpath>
    <path refid="class.path"/>
     </classpath>
  </java>
</target>
<target name="compile-all" depends="cxfJavaToWSDL">
    <javac debug="on" destdir="${classes}">
        <src path="${genCode.dir}"/>
        <classpath refid="class.path"/>
    </javac>
</target>

以及我在 ANT 中的属性和类路径

<project name="javawsVSwsTojava" default="compile-all" basedir=".">
<property name="lib.dir" location="./WebContent/WEB-INF/lib" />
<property name="genCode.dir" location="./Java Resources/generatedcode" />
<property name="classes" location="./build/genClasses" />
<property name="wsdl.location" location="" />
<path id="class.path">
    <fileset dir="${lib.dir}/dependencies">
        <include name="**/*.jar" />
    </fileset>
</path>
4

2 回答 2

1

只是因为类路径,当我们想要 java2ws 时,我们必须给一个 SEI 的类文件(编译),而不应该给 java(src)

<target name="cxfJavaToWSDL" depends="compile-all">
    <echo> ************Genarating JavaToWSDL************* </echo>
    <java classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true">
        <arg value="-wsdl" />
        <arg value="-o" />
        <arg value="${lib.dir}/CalServiceService.wsdl" />
        <arg
            value="com.saravana.webservice.services.CalService" /><!--you  should give fully qualified class name here -->
        <classpath>
            <path refid="class.path" />
        </classpath>
    </java>
</target>

我们应该在类路径中添加编译的类和依赖jar

<path id="class.path">
<pathelement location="${classes}"/>
    <fileset dir="${lib.dir}/dependencies">
        <include name="**/*.jar" />
    </fileset>
</path>

这解决了我的问题。

于 2016-05-11T08:50:44.333 回答
0

看来您需要稍微修改您的 ant 文件才能使其正常工作。java2wsdl在你的任务中试试这个

<java classname="org.apache.cxf.tools.java2ws.JavaToWS" fork="true">
  <arg value="-wsdl"/>
      <arg value="-classdir"/>
      <arg value="${classes}"/>
     <arg value="-cp"/>
      <arg value="${classes}/"/>
       <arg value="-o"/>
     <arg value="${lib.dir}/CalServiceService.wsdl"/>
     <arg value="com.saravana.webservice.services.CalServiceService"/>
     <classpath>
        <path refid="class.path"/>
         <pathelement location="${classes}/**/*.class"/> 
     </classpath>
  </java>
于 2016-05-11T06:07:42.700 回答