我正在处理一个遗留应用程序,它使用org.apache.tools.ant.taskdefs
包生成Javadoc文档。在这里,我需要使用由Maven提供的类路径。该类路径通常包含Maven本地存储库中的jar路径。
Javadoc javadoc = new Javadoc();
javadoc.setUseExternalFile(true);
javadoc.setProject(proj);
javadoc.setClasspath(new Path(proj, classpath));
问题在于类路径太长,因此在Windows上无法执行,导致出现以下错误。
enterJavadoc failed: java.io.IOException: Cannot run program "C:\jdk1.8.0_144\bin\javadoc.exe": CreateProcess error=206, The filename or extension is too long code here
对于这个问题,我的做法是创建一个路径jar包,并在其清单文件中包含长类路径。因此,我将此jar文件添加为Javadoc任务的类路径。我使用Ant中的ManifestClassPath任务生成长类路径中jar包的相对路径。
ManifestClassPath mc = new ManifestClassPath();
mc.setProject(proj);
mc.addClassPath(new Path(proj, classPath));
mc.setJarFile(new File(pathingJar));
mc.setProperty("classpath");
mc.setMaxParentLevels(20);
mc.execute();
Jar jar = new Jar();
Manifest manifest = new Manifest();
Manifest.Attribute attribute = new Manifest.Attribute();
attribute.setName("Class-Path");
attribute.setValue(proj.getProperty("classpath"));
manifest.addConfiguredAttribute(attribute);
jar.addConfiguredManifest(manifest);
jar.setDestFile(new File(pathingJar));
jar.setProject(proj);
jar.execute();
javadoc.setClasspath(new Path(proj, pathingJar));
这个解决方案在我把它开发在与maven本地库相同的驱动器上时有效。但是,当maven本地库位于不同的驱动器上时,它会失败,因为无法为不同驱动器生成相对路径。然后我尝试使用文件协议处理类路径,如下所示。
Class-Path: file:///C:/mvn_repo/... file:///C:/mvn_repo/... ...
这个解决方案似乎无法正常工作,因为Javadoc任务失败了。是否有其他方法尝试使用路径jar来解决这个长类路径问题?
mklink /J "mvn_repo_link" "C:\mvn_repo"
。然后你就可以通过mvn_repo_link
目录使用相对路径了。 - Genu