Monday, March 14, 2016

Maven antrun java.io.IOException: "Cannot run program" because "The filename or extension is too long"

There is an issue on where the command that maven antrun fails to run a java because the command line is too long.
In my case the classpath was way too long.

To fix it the classpath needs to be written to a manifest in a jar file and that needs to be used by java to get the classpath.

Here is an example of how to do it:


<manifestclasspath property="manifest.classpath"
                   jarfile="target/classpathSupplier.jar"
                   maxParentLevels="99">
    <classpath refid="maven.compile.classpath" />
</manifestclasspath>
<!-- Create pathing Jar --><jar destfile="target/classpathSupplier.jar">
    <manifest>
        <attribute name="Class-Path" value="${manifest.classpath}"/>
    </manifest>
</jar>
<java classname="org.me.ClassToRun" fork="yes" failonerror="true">
    <arg value="-someArg" />
    <!--<jvmarg value="-Xdebug"/>-->
    <!--<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>-->
    <classpath>
        <pathelement location="target/classpathSupplier.jar"/>
    </classpath>
</java>

No comments:

Post a Comment