【问题标题】:TeamCity can't find javac, trying to run a build config with an ant build stepTeamCity 找不到 javac,尝试使用 ant 构建步骤运行构建配置
【发布时间】:2014-09-06 17:04:57
【问题描述】:

这是我得到的错误: 编译错误:javac 找不到类:org.eclipse.jdt.core.JDTCompilerAdapter

我正在尝试使用 ant 构建步骤运行构建配置并不断收到此错误。 据我所知,我已经正确设置了环境变量,并且我认为 TeamCity 附带了编译 .java 文件所需的一切,为什么它找不到 javac.exe?

告诉我我可以提供哪些细节。可以在此处找到存储库:https://code.google.com/p/ci-research-teamcity-test-project/source/browse

【问题讨论】:

  • 您运行的是 Windows 版本的 TeamCity 吗?它附带捆绑的 JRE not JDK(与 Tomcat 和 Java 1.7 JRE 捆绑的可执行 Windows 安装程序)
  • 是的,我正在运行 Windows 版本,我认为是 7.x。那么我该如何将 TC 引导到 JDK?我已经制作了一个全球环境。 var 使用 JDK 路径的值调用 JDK_HOME。我也尝试在构建配置中这样做。
  • @DavidPostill 我会看一下 TC7 文档,而不是 TC8。我很确定我已经正确设置了 JDK_HOME 路径,它设置为:C:\Program Files\Java\jdk1.8.0_20 同样在构建配置中我对配置参数做了同样的事情(将 JDK_HOME 设置为C:\Program Files\Java\jdk1.8.0_20)

标签: java eclipse ant teamcity buildconfiguration


【解决方案1】:

错误出现在 build.xml 脚本中。
我正在使用 Eclipse 提供的生成的 build.xml:

<?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>

这是我的 build_custom.xml,它已经过精简和简化:
(注意 javac 任务中的 compiler="modern" 属性,这修复了我得到的另一个错误,即 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>

【讨论】:

  • 这不是答案。这是对原始问题的评论或(更好)编辑。
猜你喜欢
  • 2014-09-13
  • 1970-01-01
  • 2013-02-21
  • 2014-02-05
  • 2018-08-19
  • 1970-01-01
  • 2012-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多