I am working on a legacy application where it uses Javadoc generation using ant task by using the package org.apache.tools.ant.taskdefs
. There I need to pass the classpath given by the maven. this classpath mostly has jar paths in the maven local repository.
Javadoc javadoc = new Javadoc();
javadoc.setUseExternalFile(true);
javadoc.setProject(proj);
javadoc.setClasspath(new Path(proj, classpath));
The problem is this classpath is long enough so that execution on Windows is not permitted which cause the following error.
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
For this problem what I did was to create a pathing jar which includes the long classpath in its manifest file. So I add this jar file as the classpath for Javadoc task. I used ManifestClassPath task in the ant to generate relative paths for the jars in my long classpath.
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));
This solution works until I develop this in the same drive where the maven local repository is located. But maven local repository is located in a different drive it fails as it can't generate a relative path for a different drive. Then I tried with processing classpath by using the file protocol like following
Class-Path: file:///C:/mvn_repo/... file:///C:/mvn_repo/... ...
This solution did not seem to be working as the Javadoc task is failing. Is there any other approach to try using a pathing jar to fix this long classpath issue?
As mentionned by @MarquisofLorne, you can't.
Class-path entries in the Manifest are relative URLs
Anyway, you can use a workaround with a folder link. On the drive of your pathing jar, you can create a folder link to the maven directory. Folder links can point to another drive.
mklink /J "mvn_repo_link" "C:\mvn_repo".
And then you can use relative path through mvn_repo_link
subdirectory