java.lang.classnotfoundexception for junit with ant

时间:2014-05-05 10:27:12

标签: java ant junit

我的构建xml如下所示。在通过ant运行junit类时,它没有给出类def错误。

                            

<import file="${devenv.dir}/DevEnv.xml" />
<import file="${devenv.dir}/cm.xml" />
<import file="${devenv.dir}/wls.xml" />
<import file="${devenv.dir}/wls-build.xml" />
<import file="${devenv.dir}/xboss.xml" />
<import file="${devenv.dir}/generate.xml" />

<!-- filterset for ConfigSetup, controled with target.env -->
<filterset id="configsetup.filterset" begintoken="@" endtoken="@">
    <!-- Used in config/*/ear/META-INF/application.xml -->
    <filter token="DevEnvVersion" value="${cs.devenv.version}" />

    <!-- Used in config/*/setup/build.properties -->
    <filter token="BEA_HOME" value="${bea.home}" />
    <filter token="WEBLOGIC_HOME" value="${weblogic.home}" />
    <filter token="DOMAIN_DIR" value="${domain.dir}" />
    <filter token="WLS_SERVERNAME" value="${wls.servername}" />
    <filter token="WLS_DOMAINNAME" value="${wls.domainname}" />
    <filter token="WLS_HOST" value="${wls.host}" />
    <filter token="WLS_PORT" value="${wls.port}" />
    <filter token="WLS_USERNAME" value="${wls.username}" />
    <filter token="WLS_PASSWORD" value="${wls.password}" />
    <filter token="WEBLOGICSERVER_CLASSPATH" value="${cs.weblogicserver.classpath}" />
    <filter token="MODULE_VERSION" value="${version.release.number}" />
</filterset>
                        <!--  Jenkins implementation  --> 
        <property name="dir.src" location="src" />
        <property name="dir.bin" location="bin"/>
        <property name="dir.bintest" location="${basedir}/bin/test"/>
        <property name="dir.srctest" location="${basedir}/src/test" /> 
        <property name="dir.build.test.classes" location="${basedir}/build/classes/test" /> 
        <property name="dir.dist" location="${basedir}/build/dist" /> 
        <property name="weblogic.home" location="T:/bea/wlserver_10.3" /> 
        <property name="jar.webservices" location="${weblogic.home}/server/lib/webservices.jar" />
        <property name="dir.classes" location="${basedir}/build/classes" /> 
        <property name="dir.dist" location="${basedir}/dist" /> 
        <property name="dir.config" location="${basedir}/config" /> 
        <property name="dir.junit.rep" location="${basedir}/build/junitoutput" />  
        <property name="dir.resources" location="${basedir}/resources" /> 
        <property name="dir.src" location="${basedir}/src" />  
        <property name="jar.junit" location="T:/External/JUnit/3.8.1/junit.jar" /> 
        <property name="jar.weblogic" location="${weblogic.home}/server/lib/weblogic.jar"/>
        <property name="jar.XMLBroker" location="T:/EAIUTIL/Xbroker"/>
        <property name="jar.apt-jelly" location="T:/External/apt-jelly/2.3//apt-jelly-2.3.jar"/>
        <property name="jar.DodLink" location="D:/junitttest/DokLink_WLS10/build/lib/DodLink.jar"/>
        <property name="jar.DodLink-client" location="D:/junitttest/DokLink_WLS10/build/lib/DodLink-client.jar"/>
        <property name="jar.DodLink-xmlbean" location="D:/junitttest/DokLink_WLS10/build/lib/DodLink-xmlbean.jar"/>
        <property name="jar.DokLink-MapperUtil-4_0-client" location="D:/junitttest/DokLink_WLS10/build/lib/DodLink-MapperUtil-4_0-client.jar"/> 


<target name="create-deployed-domain" description="Delete the old domain and create and deploy on a new domain" depends="load.taskdef.antcontrib">
    <delete dir="${basedir}/domain"/>
    <echo>Processing create and start domain...</echo>
    <antclasspath target="create-and-setup-domain" classpath="" antopt=""/>
            <antcall target="wls.start-local"/>
            <sleep seconds="10"/>
    <antcall target="wls.deploy"/>
</target>
<target name="create-and-setup-domain" depends="wls.create-domain, wls.setup-domain"/>

<target name="local.build.target">
    <echo message="Local build target called" />
</target>

<target name="eclipse.refresh" if="eclipse.running">
    <eclipse.refreshLocal resource="${basedir}" depth="infinite"/>
</target>

<target name="ensure-prod-target">
    <if>
        <equals arg1="${target.env}" arg2="prod" trim="true"/>
        <then/>
        <else>
            <fail>The property 'target.env' must be 'prod'.</fail>
        </else>
    </if>

</target>



<target name="publish-release" description="Publish a release by making one and copying it to the relase share" depends="ensure-prod-target,all">
    <mkdir dir="${release.dir}"/>

    <copy todir="${release.dir}">
        <fileset dir="${build.lib.dir}" includes="${app.name}-${cm.tag}-schema.jar"/>
        <fileset dir="${build.lib.dir}" includes="${jar.filename}"/>
        <fileset dir="${build.lib.dir}" includes="${client.filename}"/>
        <fileset dir="${build.lib.dir}" includes="${client.executer.filename}"/>
        <fileset dir="${dist.lib.dir}" includes="${ear.filename}"/>
    </copy>
</target>

<target name="build.executer.client">
        <property name="build.config.client.executer.dir" value="${build.config.dir}/client-executer"/>

        <mkdir dir="${build.lib.dir}" />

        <mkdir dir="${build.config.client.executer.dir}/META-INF" />

        <tstamp>
            <format property="current_time" pattern="dd-MM-yyyy HH:mm:ss" locale="dk" />
        </tstamp>

        <manifest file="${build.config.client.executer.dir}/META-INF/MANIFEST.MF">
            <attribute name="Manifest-version" value="1.0" />
            <attribute name="Built-By" value="${user.name}" />
            <attribute name="Implementation-Title" value="${client.executer.title}" />
            <attribute name="Implementation-Version" value="${client.executer.version}" />
            <attribute name="Implementation-Vendor" value="${client.executer.vendor}" />
            <attribute name="Implementation-Buildtime" value="${current_time}" />
        </manifest>

        <jar jarfile="${build.lib.dir}/${client.executer.filename}" manifest="${build.config.client.executer.dir}/META-INF/MANIFEST.MF">
            <fileset dir="${classes.main.dir}" includes="dk/tdc/soa/inventory/extern/datatypes/*,
                                                         dk/tdc/soa/inventory/intern/commonfunctions/*,
                                                         dk/tdc/soa/inventory/intern/constants/*,
                                                         dk/tdc/soa/inventory/intern/datatypes/*,
                                                         dk/tdc/soa/inventory/intern/mapper/*,
                                                         dk/tdc/soa/inventory/intern/util/*,
                                                         dk/tdc/soa/inventory/intern/datatypes/errortypes/XMLParserException.class,
                                                         dk/tdc/soa/inventory/intern.communication/XmlFactory.class"/>
        </jar>
    </target>

<target name="dist.executer.client">
        <copy todir="${dist.dir}/lib/">
            <fileset dir="${build.lib.dir}">
                <include name="${client.executer.filename}"/>
            </fileset>
        </copy>
    </target>

                     <!--  Junit test  -->
        <target name="runtest" description="Runs the test you specify">
        <mkdir dir="${basedir}/build/junitreport"/> 
        <junit printsummary="yes" fork="yes">
        <classpath>
        <pathelement path="${dir.build.test.classes}" />    
        <pathelement path="${jar.junit}" />     
        <pathelement path="${jar.weblogic}"/>
        <pathelement path="${jar.XMLBroker}"/>
        <pathelement path="${jar.apt-jelly}"/>      
        <pathelement path="${jar.DokLink}"/>
        <pathelement path="${jar.DokLink-client}"/> 
        <pathelement path="${jar.DokLink-xmlbean}"/>
        <pathelement path="${dir.bintest}"/>
        <pathelement path="${dir.classes}"/>
        </classpath>

        <formatter type="xml"/>
        <batchtest fork="no" todir="${dir.junit.rep}">
        <fileset dir="${dir.srctest}" includes="**/RemoteDokLink.java"/>
        </batchtest>
        </junit>
        </target>

junit类在运行时可以完美地运行文件,但是当我从ant调用它时,会出现以下错误

<testcase classname="td.soa.inventory.test.RemoteDodLink" name="testGetFaultMark" time="0.021">
 <error message="td/devenv/exceptions/EjbDelegateException" type="java.lang.NoClassDefFoundError">java.lang.NoClassDefFoundError:      dk/tdc/devenv/exceptions/EjbDelegateException at dk.tdc.soa.inventory.test.RemoteDodLink.testGetFaultMark(RemoteDokLink.java:48) at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets  (EclipseDefaultExecutor.java:32) at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424) at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138) Caused by: java.lang.ClassNotFoundException: dk.tdc.devenv.exceptions.EjbDelegateException at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

任何人都可以帮助我吗?提前致谢

1 个答案:

答案 0 :(得分:0)

您需要在ant classpath中设置包含异常的jar。

请参阅任何文档 http://ant.apache.org/manual/using.html

http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html