NoClassDefFoundError when using a jar builded with ant script in TeamCity


I've started using TeamCity recently and i just add the tests with code coverage yesterday. The tests and the code coverage work fine, but when i want to use the generated Jar, i've an error :

Exception in thread "JTheque First Phase Launching" java.lang.NoClassDefFoundError: com/vladium/emma/rt/RT
    at org.jtheque.films.stats.StatsModule.$VRi(
    at org.jtheque.films.stats.StatsModule.<clinit>(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at org.jtheque.core.managers.module.loaders.SystemModuleLoader.getModuleFiles(
    at org.jtheque.core.managers.module.ModuleManager.loadModules(
    at org.jtheque.core.managers.application.Application$
Caused by: java.lang.ClassNotFoundException: com.vladium.emma.rt.RT
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClassInternal(
    ... 7 more

I know that Emma is the code coverage tool that i use, but i don't want to integrate emma.jar in the application i develop. I need the code coverage, but the clients of the application doesn't want that.

The jar is builded with an ant script launched by teamcity :

<?xml version="1.0" encoding="UTF-8"?>
<project name="JTheque Stats Module" basedir="." default="tests">
    <target name="init">
        <property name="" value="JTheque Stats Module"/>
        <property name="workspace" value="N:/Programmation/Workspaces/Intellij Idea Workspace/"/>
        <property name="jtheque.workspace" value="${workspace}/JTheque"/>
        <property name="jtheque.dir" value="N:\Programmation\WorkDirectory\JTheque\current"/>
        <property name="jtheque.out" value="${jtheque.workspace}/out/production"/>
        <property name="project.root.dir" value="${jtheque.workspace}/${}"/>
        <property name="project.src.dir" value="${project.root.dir}/src"/>
        <property name="project.bin.dir" value="${jtheque.out}/${}"/>
        <property name="output.jar.dir" value="${jtheque.dir}/modules/"/>
        <property name="test" value="/org/jtheque/films/stats/tests"/>
        <property name="junit.jar" value="${jtheque.workspace}\JTheque Tests\lib\junit-4.5.jar"/>

    <!-- Clean build directory -->
    <target name="clean" depends="init">
        <delete dir="${project.bin.dir}" includeEmptyDirs="true"/>

    <!-- Compile java files -->
    <target name="compile" depends="clean">
        <path id="master-classpath">
            <path id="libs" location="${jtheque.dir}">
                <fileset dir="${jtheque.dir}/lib/" includes="*.jar">
                    <include name="**/*.jar"/>
                    <include name="*.jar"/>
            <path id="modules" location="${jtheque.dir}">
                <fileset dir="${jtheque.dir}/modules/">
                    <include name="*.jar"/>
            <path refid="libs"/>
            <path refid="modules"/>
            <pathelement path="${java.class.path}"/>
            <pathelement location="${jtheque.dir}\JTheque-Core.jar"/>
            <pathelement location="${junit.jar}"/>

        <mkdir dir="${project.bin.dir}"/>
        <javac srcdir="${project.src.dir}" destdir="${project.bin.dir}"
               fork="true" source="1.6" target="1.6">
            <classpath refid="master-classpath"/>

    <!-- Build JAR files-->
    <target name="buildJar" depends="compile">
        <delete file="${output.jar.dir}/JTheque-Stats-Module.jar"/>
        <jar destfile="${output.jar.dir}/JTheque-Stats-Module.jar"
             basedir="${project.bin.dir}" manifest="MANIFEST.MF"/>

    <!-- Tests the compiled classes-->
    <target name="tests" depends="buildJar">
        <junit printsummary="yes" showoutput="true" fork="true" forkmode="once">
            <classpath refid="master-classpath"/>
            <formatter type="xml" usefile="no"/>
                <fileset dir="${project.src.dir}">
                    <include name="${test}/*"/>

How can i build the jar and make it completely independant of Emma ? Must i create two build configuration ? One with Code Coverage and one without ? I think it is not optimal...

Thank you for helping.

Have a Good day


Comment actions Permalink


The current approach is either to use two build configurations (one for gathering coverage and one for building production version) or do the same two tasks in your build script. If you need to obtain the coverage and build production version you for every checkin you can use TeamCity snapshot dependecnies.

You may want to vote for the issue we already have filed on the topic:

Comment actions Permalink

Hi !

Thank you for responding, i'll try to duplicate my build configurations, but it made a lot of build configurations...

I've voted for the issue. I think it's very important missing thing.


Please sign in to leave a comment.