Maven和Ant可以';t运行Java-CreateProcess error=206,文件名或扩展名太长
当maven通过antrun执行这段java代码时,我得到了可怕的错误=206,文件名或扩展名太长Maven和Ant可以';t运行Java-CreateProcess error=206,文件名或扩展名太长,maven,ant,maven-antrun-plugin,Maven,Ant,Maven Antrun Plugin,当maven通过antrun执行这段java代码时,我得到了可怕的错误=206,文件名或扩展名太长 <java classname="com.me.api" failonerror="true" fork="true" maxmemory="128m" output="${wsdlFile}.out"> <arg value="${className}" /> <arg value="${name}" /> <arg value="${wsd
<java classname="com.me.api" failonerror="true" fork="true" maxmemory="128m" output="${wsdlFile}.out">
<arg value="${className}" />
<arg value="${name}" />
<arg value="${wsdlFile}" />
<classpath>
<path refid="maven.test.classpath" />
</classpath>
由于本地Maven repo的结构和位置,Maven会创建很长的类路径。我们需要使用一个路径jar
- 将类路径转换为字符串
- 转义windows驱动器号(C:=坏\C:=好)
- 使用类路径属性创建仅清单jar
- 使用路径jar而不是maven编译类路径
如果使用Ant 1.7或更新版本,您可以利用manifestclasspath任务生成清单文件,然后将其包含在jar中,以便在javac类路径上使用
扩展@user4386022提供的答案:您可以定义(从Ant 1.8开始)这个宏,如果您在构建过程中的不同地方遇到相同的问题,它可以帮助您(并且您不能只是复制粘贴相同的代码段,因为Ant不允许重新定义属性,所以您将得到一个错误,说明“manifest.classpath”已定义。)
要在目标或任务中使用宏,只需如下使用:
<path id="myclasspath">
.........
</path>
<create-classpath-jar classpathjar="classpath-compile.jar" classpathref="myclasspath" />
.........
通过删除fork=“true”修复了问题“
来自build.xml文件中的javac目标。如果生成过程中必须使用分叉,请参考上述解决方案。您将此粘贴到何处?pom文件的build部分?@Jocelyn您将其作为maven-antrun插件的一部分放在pom部分。请参考maven antrun插件,事情应该是清楚的。请注意,使用org.apache.axis.wsdl.WSDL2Java时,可以使用相同的宏解决Windows上出现的“CreateProcess error=87,参数不正确”问题
<!-- turn the classpath into a property formatted for inclusion in a MANIFEST.MF file -->
<manifestclasspath property="manifest.classpath"
jarfile="${classpath-compile.jar}">
<classpath refid="maven.compile.classpath" />
</manifestclasspath>
<!-- Create pathing Jars -->
<jar destfile="${classpath-compile.jar}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
<java classname="com.me.api" failonerror="true" fork="true" maxmemory="128m" output="${wsdlFile}.out">
<arg value="${className}" />
<arg value="${name}" />
<arg value="${wsdlFile}" />
<classpath>
<pathelement location="${classpath-compile.jar}" />
</classpath>
<macrodef name="create-classpath-jar" description="Create classpath Jar, to avoid getting the error about CreateProcess error=206, The filename or extension is too long">
<attribute name="classpathjar"/>
<attribute name="classpathref"/>
<sequential>
<!-- Turn the classpath into a property formatted for inclusion in a MANIFEST.MF file -->
<local name="manifest.classpath.property"/>
<manifestclasspath property="manifest.classpath.property" jarfile="@{classpathjar}">
<classpath refid="@{classpathref}" />
</manifestclasspath>
<!-- Create the Jar -->
<jar destfile="@{classpathjar}">
<manifest>
<attribute name="Class-Path" value="${manifest.classpath.property}"/>
</manifest>
</jar>
</sequential>
</macrodef>
<path id="myclasspath">
.........
</path>
<create-classpath-jar classpathjar="classpath-compile.jar" classpathref="myclasspath" />