Can I deny javac access to Class-Path from the manifest of our third-party banks?

Since Java 1.5 or so, javac is exploring the manifest of third-party jars to find other jars. This causes a number of unwanted side effects:

  • When the jar files have been renamed, now we get a stream of warnings whenever we compile (can be resolved with -Xlint:-path )
  • Files that we do not want on the way to the classes are returned to it, even if they were left for some reason.
  • In the assembly, additional time is added to search for all these additional cans due to the permission of this material, which we really do not want.

So I was wondering if anyone knows the magic call to disable this. Assuming that the Sun did not saddle us with another feature that we did not want and cannot turn off as soon as we get it.

+6
java classpath jar manifest javac
source share
2 answers

Heres a Ant target for modifying manifest files (uses ant -contrib)

 <target name="util-modify-manifest" depends="build-classpath"> <for param="file"> <fileset dir="${jars}" > <include name="**/*.jar" /> </fileset> <sequential> <jar jarfile="@{file}" destfile="@{file}" update="true"> <manifest> <attribute name="Class-Path" value="" /> <attribute name="Export-Package" value="" /> </manifest> </jar> <echo message="Manifest Replaced: @{file}" /> </sequential> </for> 

+2
source share

Use bnd or shade to disconnect the MANIFEST.MF entry from banners, and not just rename it. Or take advantage of the fact that these paths are never absolute. If you move the jug named "i-have-a-ClassPath.jar" to your own subdirectory, manifest manifest path entries will not be able to find these other banks in the expected locations. I suppose it will whine anyway if you turn on enough nap.

+1
source share

All Articles