当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="${wsdlFile}" />
<classpath>
<path refid="maven.test.classpath" />
</classpath>
答案 0 :(得分:4)
由于本地maven repo的结构和位置,Maven创建了冗长的类路径。我们需要使用一个路径jar。
<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>
答案 1 :(得分:3)
扩展@ user4386022提供的答案:您可以定义(从Ant 1.8开始)这个宏,如果您在构建过程中的不同位置遇到同样的问题,它可以帮助您(并且您不能只复制粘贴相同的片段因为Ant不允许重新定义属性,所以你会得到一个错误,说明&#34; manifest.classpath&#34;已经定义了。)
<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" />
答案 2 :(得分:1)
如果使用Ant 1.7或更新版本,您可以利用manifestclasspath任务生成清单文件,然后将其包含在jar中以便在javac类路径上使用
<!-- 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>
答案 3 :(得分:0)
通过从build.xml文件中的javac目标中删除fork="true"
来解决问题。如果在构建过程中必须进行分叉,请参考上面的解决方案。