JavaC CreateProcess error=206, The filename or extension is too long

antjavajavacJenkins

I tried to compile java code, but I got the error:
Caused by: java.io.IOException: Cannot run program "C:\jdk\bin\javac": CreateProcess error=206, The filename or extension is too long.

This is the content of my build file:

 <path id="was.runtime">
            <!-- <fileset dir="C:\Users\Administrator\.jenkins\workspace\BUILD2TEST\BUILD2TEST\WebContent\WEB-INF\lib">
                <include name="*.jar"/>
              </fileset> -->          
             <fileset dir="${copy.from.path}/WebContent/WEB-INF/lib">
                <include name="*.jar" />
            </fileset> 
            <fileset dir="${was_home}/lib">
                <include name="**/*.jar" />
            </fileset>
            <fileset dir="${was_home}/plugins">
                <include name="**/*.jar" />
            </fileset>

      </path>
        <property name="was_cp" value="${toString:was.runtime}" />


<javac fork="yes" executable="${java.home}/bin/javac" compiler="javac1.6" includeantruntime="false" encoding="utf-8" srcdir="${workspace}/${project.name}/src" destdir="${workspace}/${project.name}/WebContent/WEB-INF/classes" classpath="${was_cp}">
                </javac>

I think maybe my classpath: ${was_cp} is too long. How can I fix this ?

Best Answer

The problem isn't that your classpath is too large. It's that you're converting into one gigantic string. Simply use the classpathref attribute instead:

<path id="was.runtime">        
    <fileset dir="${copy.from.path}/WebContent/WEB-INF/lib">
        <include name="*.jar" />
    </fileset> 
    <fileset dir="${was_home}/lib">
        <include name="**/*.jar" />
    </fileset>
    <fileset dir="${was_home}/plugins">
        <include name="**/*.jar" />
    </fileset>
</path>

<javac
    fork="yes"
    executable="${java.home}/bin/javac"
    compiler="javac1.6"
    includeantruntime="false"
    encoding="utf-8"
    srcdir="${workspace}/${project.name}/src"
    destdir="${workspace}/${project.name}/WebContent/WEB-INF/classes"
    classpathref="was.runtime"
/>
Related Topic