NoClassDefFoundError when using a jar builded with ant script in TeamCity

Hi,

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(StatsModule.java)
    at org.jtheque.films.stats.StatsModule.<clinit>(StatsModule.java)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at org.jtheque.core.managers.module.loaders.SystemModuleLoader.getModuleFiles(SystemModuleLoader.java:80)
    at org.jtheque.core.managers.module.ModuleManager.loadModules(ModuleManager.java:222)
    at org.jtheque.core.managers.application.Application$FirstPhaseLauncherThread.run(Application.java:356)
Caused by: java.lang.ClassNotFoundException: com.vladium.emma.rt.RT
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    ... 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="project.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}/${project.name}"/>
        <property name="project.src.dir" value="${project.root.dir}/src"/>
        <property name="project.bin.dir" value="${jtheque.out}/${project.name}"/>
        <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"/>
    </target>

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

    <!-- 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"/>
                </fileset>
            </path>
            <path id="modules" location="${jtheque.dir}">
                <fileset dir="${jtheque.dir}/modules/">
                    <include name="*.jar"/>
                </fileset>
            </path>
            <path refid="libs"/>
            <path refid="modules"/>
            <pathelement path="${java.class.path}"/>
            <pathelement location="${jtheque.dir}\JTheque-Core.jar"/>
            <pathelement location="${junit.jar}"/>
        </path>

        <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"/>
        </javac>
    </target>

    <!-- 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"/>
    </target>

    <!-- 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"/>
            <batchtest>
                <fileset dir="${project.src.dir}">
                    <include name="${test}/*Test.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>
</project>


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

Baptiste

2 comments
Comment actions Permalink

Hi!

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: http://jetbrains.net/tracker/issue2/TW-6622

0
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.

0

Please sign in to leave a comment.