Maven和Ant无法运行Java-CreateProcess错误= 206,文件名或扩展名太长
问题描述:
当通过antrun的maven执行此Java代码时,出现可怕的错误= 206,文件名或扩展名太长
When maven via antrun executes this java code I get the dreaded error=206, The filename or extension is too long
<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存储库的结构和位置,Maven创建了冗长的类路径.我们需要使用一个路径罐子.
Maven creates lengthy classpaths due to the structure and location of the local maven repo. We need to use a pathing jar.
- 将Classpath转换为字符串
- 转义Windows驱动器号(C:=坏\ C:=很好)
- 创建具有类路径属性的仅清单jar
- 使用路径jar代替maven编译classpath
<mkdir dir="${classpath-compile.dir}"/>
<!-- Convert into usable string . -->
<pathconvert property="compile_classpath_raw" pathsep=" ">
<path refid="maven.compile.classpath"/>
</pathconvert>
<!-- escape windows drive letters (remove C: from paths -- need to wrap with a condition os.family="windows")-->
<propertyregex property="compile_classpath_prep"
input="${compile_classpath_raw}"
regexp="([A-Z]:)"
replace="\\\\\1"
casesensitive="false"
global="true"/>
<!-- Create pathing Jars -->
<jar destfile="${classpath-compile.jar}">
<manifest>
<attribute name="Class-Path" value="${compile_classpath_prep}"/>
</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>