如何设置java2ws类路径?

时间:2013-01-31 12:24:49

标签: java web-services cxf

当我尝试生成wsdl文件时,我正在

JavaToWS Error: org.apache.cxf.tools.common.ToolException: Fail to load class : com.oprs.ws.AvailableServiceWS

错误。调试后我发现java2ws类路径已经设置为/Projects/Txt2ORA/WS-client-oprs/build/classes,我没有任何类。我需要为java2ws设置类路径,但没有找到方法。在哪里设置这条路径?

我正在使用CXF 2.6.0。

EDIT build.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- This is the common header that should be included for every build.xml script file -->
<!DOCTYPE project [
    <!ENTITY load-flag-targets SYSTEM "file:../../../flag-targets.xml">
    <!ENTITY set-properties SYSTEM "file:../../../includes.xml">
]>

<project basedir="." default="build" name="Cxf_WebServices">

    <!-- define all settings for different kinds of builds -->
    &load-flag-targets;

    <target name="--init" unless="project.base">
        <echo message="** Setting properties . . ."/>
        <!-- Read the system environment variables and stores them in properties, -->
        <!-- prefixed with "env.". -->
        <property environment="env."/>

        <!-- The build.properties file defines the project base and lib directories -->
        <property file="../../../build.properties"/>

        <!-- set the properties based on the build flags -->
        &set-properties;
    </target>

    <target name="init" depends="--init">
        <property name="output" value="build/classes/${build.dir}"/>
        <property name="input" value="main"/>
        <property name="jarfile" value="oprs-ws.jar"/>
        <property name="dist" value="build/dist/${build.dir}"/>
        <property name="javadoc.dir" value="build/javadoc"/>
        <property name="javadoc.name" value="oprs-ws-javadocs.zip"/>
        <property name="custom.lib" value="${components.dist.dir}"/>
        <property name="wsdl.dir" value="${war.staging}/wsdl"/>
        <mkdir dir="${output}"/>
    </target>

    <target name="compile" depends="init">
        <javac debug="${compile.debug}" debuglevel="${compile.debug.level}" deprecation="true" 
                destdir="${output}" srcdir="${input}" includeantruntime="false">
            <classpath>
                <fileset dir="${project.lib}">
                    <include name="*.jar"/>
                    <include name="${flags.server}/*.jar"/>
                    <include name="struts/*.jar"/>
                    <include name="cxf-spring/*.jar"/>
                </fileset>
        <fileset dir="${custom.lib}">
            <include name="**/*.jar"/>
        </fileset>
            </classpath>
        </javac>
    </target>

    <target name="jar" depends="init,compile">
        <jar jarfile="${output}/${jarfile}" compress="true" excludes="*.jar" manifest="META-INF/MANIFEST.MF">
            <fileset dir="${output}">
                <include name="**/*.class"/>
            </fileset> 
            <fileset dir=".">
                <include name="META-INF/*.xml"/>
            </fileset>  
        </jar>
    </target>

    <target name="cxf-WSDL2Java" depends="build">
        <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
            <arg value="-verbose" />
            <arg value="-validate" />
            <arg value="-compile" />
            <arg value="-d" />
            <arg value="${input}" />
            <arg value="-classdir" />
            <arg value="${output}" />
            <arg value="${wsdl.dir}/TicketBookingService.wsdl" />

            <classpath>
                <fileset dir="${project.lib}">
                    <include name="*.jar"/>
                    <include name="${flags.server}/*.jar"/>
                    <include name="cxf-spring/*.jar"/>
                    <include name="${cxf.home}/modules/*.jar"/>
                    <include name="${cxf.home}/lib/*.jar"/>
                </fileset>
                <fileset dir="${custom.lib}">
                    <include name="**/*.jar"/>
                </fileset>
            </classpath>
        </java>
    </target>


    <target name="build" depends="init,jar" description="Build release jar.">
        <copy file="${output}/${jarfile}" todir="${components.dist.dir}" overwrite="true"/>
        <echo message="Built ${jarfile} for ${flags.mode} ${flags.server} ${flags.os} in ${components.dist.dir}."/>
    </target>

    <target name="clean" depends="init" description="Clean all build products.">
        <delete dir="${output}" quiet="true"/>
        <delete dir="${javadoc.dir}" quiet="true"/>
        <delete dir="${dist}" quiet="true"/>
    </target>

    <!-- generate javadoc, zip it and send it to a stage location. Ignore errors. -->
    <target name="javadoc" depends="init">
        <mkdir dir="${javadoc.dir}"/>

        <!-- generate javadoc -->
        <javadoc destdir="${javadoc.dir}"
                windowtitle="Package: oprs CXF Web Services"
                author="false"
                version="false"
                excludepackagenames="org.*,javax.*"
                verbose="false">

            <classpath>
                <fileset dir="${project.lib}">
                    <include name="*.jar"/>
                    <include name="${flags.server}/*.jar"/>
                </fileset>
                <fileset dir="${custom.lib}">
                    <include name="*.jar"/>
                </fileset>
            </classpath>

            <packageset dir="${input}" defaultexcludes="yes">
                <include name="com/abhibus/oprs/**" />
            </packageset>
        </javadoc>

        <!-- zip javadoc -->
        <zip destfile="${components.javadoc.dir}/${javadoc.name}" basedir="${javadoc.dir}"/>

        </target>

        <!-- Deploy the jar file for developement testing purpose only -->
        <target name="deploy-jar" depends="build">
            <copy file="${components.dist.dir}/${jarfile}" todir="${deploy.dir}/apsrtc-oprs/WEB-INF/lib" overwrite="true"/>
        </target>

</project>

1 个答案:

答案 0 :(得分:0)

只需在<pathelement path="${build.classes directory....}"/>内添加<classpath>标记即可。这解决了我的问题。