0

This is the error I'm getting: Compilation error: javac Class not found: org.eclipse.jdt.core.JDTCompilerAdapter

I'm trying to run a build config with an ant build step and keep getting this error. As far as I know I've set environment variables properly and I assume TeamCity comes with everything required to compile .java files, why can't it find javac.exe?

Tell me what details I can provide. The repository can be found here: https://code.google.com/p/ci-research-teamcity-test-project/source/browse

Petrus K.
  • 840
  • 7
  • 27
  • 56
  • Are you running the windows version of TeamCity? It comes with bundled JRE **not** JDK (Executable Windows installer bundled with Tomcat and Java 1.7 JRE) – DavidPostill Sep 06 '14 at 17:44
  • Yes, I'm running the windows version, 7.x I think.. How do I go about to directing TC to JDK then? I've already made a global env. var called JDK_HOME with the value of the JDK path.. and I've also tried doing it in the build config. – Petrus K. Sep 06 '14 at 19:16
  • http://confluence.jetbrains.com/display/TCD8/TeamCity+Documentation – DavidPostill Sep 06 '14 at 19:29
  • [Configuring Java](http://confluence.jetbrains.com/display/TCD8/Setting+up+and+Running+Additional+Build+Agents#SettingupandRunningAdditionalBuildAgents-ConfiguringJava) – DavidPostill Sep 06 '14 at 19:31
  • @DavidPostill I'll take a look at the TC7 documentation, not TC8. I'm pretty sure I've already set up the JDK_HOME path properly, it's set to: C:\Program Files\Java\jdk1.8.0_20 Also in the build config I've done the same with config parameters (setting JDK_HOME to C:\Program Files\Java\jdk1.8.0_20) – Petrus K. Sep 06 '14 at 19:46
  • Check your PATH as well. JDK_HOME\bin needs to be in the front of the path [Updating the PATH Environment Variable](http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html#path) – DavidPostill Sep 06 '14 at 19:50
  • If everything is correct then `java -version` should work from the command line. – DavidPostill Sep 06 '14 at 19:51
  • @DavidPostill Yeah I did that when I installed JDK and Eclipse. – Petrus K. Sep 06 '14 at 20:00
  • I have no more ideas :( – DavidPostill Sep 06 '14 at 20:01
  • Who do you suggest I contact? Would I be able to get help from the TeamCity devs? – Petrus K. Sep 06 '14 at 20:03
  • http://www.jetbrains.com/support/teamcity/index.html? – DavidPostill Sep 06 '14 at 20:05

1 Answers1

-1

The error was in the build.xml script.
I was working with the generated build.xml that Eclipse provides:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. --><project basedir="." default="build" name="ci-research-teamcity-test-project">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../../eclipse/"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.8"/>
    <property name="source" value="1.8"/>
    <path id="ci-research-teamcity-test-project.classpath">
        <pathelement location="bin"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="ci-research-teamcity-test-project.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
    <target name="Demo01">
        <java classname="pack1.Demo01" failonerror="true" fork="yes">
            <classpath refid="ci-research-teamcity-test-project.classpath"/>
        </java>
    </target>
    <target name="Demo02">
        <java classname="pack1.Demo02" failonerror="true" fork="yes">
            <classpath refid="ci-research-teamcity-test-project.classpath"/>
        </java>
    </target>
</project>

Here's my build_custom.xml that works, it's trimmed down and simplified:
(note the compiler="modern" attribute in the javac task, this fixed another error I got, namely Compilation error: javac - Class not found: javac1.8)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!--    Author:         Petrus K.
            Description:    A custom ant build script based on an auto-generated script by Eclipse 4.4.0
            More info:      http://ant.apache.org/manual/using.html
    -->

    <!-- project attributes -->
    <project basedir="." default="build" name="ci-research-teamcity-test-project">
        <description>
            simple ant build script for demonstrational purposes
        </description>

    <!-- properties -->
    <property name="src" location="src"/>
    <property name="bin" location="bin"/>

    <!-- paths -->
    <path id="classpath">
        <pathelement location="bin"/>
    </path>

    <!-- targets -->
    <!-- TARGET init: initializes file and folder structures before compilation -->
    <target name="init" description="initializes file and folder structures before compilation">
        <mkdir dir="bin"/>
            <copy includeemptydirs="false" todir="bin">
                <fileset dir="src">
                    <exclude name="**/*.java"/>
                </fileset>
            </copy>
        <echo message="init completed"></echo>
    </target>

    <!-- TARGET build: compiles the source -->
    <target name="build" depends="init" description="compiles the source">
        <javac srcdir="${src}" destdir="${bin}" includeantruntime="false" compiler="modern"/>
        <echo message="build completed"></echo>
    </target>

    <!-- TARGET clean: cleans the compiled files -->
    <target name="clean" description="cleans the compiled files">
        <delete dir="bin"/>
        <echo message="clean completed"></echo>
    </target>

    <!-- TARGET run: runs the demo project -->
    <target name="run" depends="build" description="runs the demo project">
        <java classname="pack1.Demo01" failonerror="true" fork="yes">
            <classpath refid="classpath"/>
        </java>
        <echo message="run completed"></echo>
    </target>

    </project>
Petrus K.
  • 840
  • 7
  • 27
  • 56