Add index to jar file, referencing external jar file

I am trying to create an index creation in a jar file. However, this fails:

$ jar -i /tmp/vtk-dicom/bin/lib/vtkdicom.jar java.io.FileNotFoundException: /tmp/vtk-dicom/bin/lib/vtk.jar (No such file or directory) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:215) at java.util.zip.ZipFile.<init>(ZipFile.java:145) at java.util.jar.JarFile.<init>(JarFile.java:154) at java.util.jar.JarFile.<init>(JarFile.java:91) at sun.tools.jar.Main.getJarPath(Main.java:1052) at sun.tools.jar.Main.getJarPath(Main.java:1068) at sun.tools.jar.Main.genIndex(Main.java:1084) at sun.tools.jar.Main.run(Main.java:269) at sun.tools.jar.Main.main(Main.java:1177) 

The obvious workaround is simple:

 $ cp /usr/share/java/vtk.jar /tmp/vtk-dicom/bin/lib/ 

However, it is ugly and error prone. Is there any other way that I can tell jar -i where to look for another vtk.jar location? I will need a portable solution that runs on Windows / Linux / MacOSX.

For information, the manifest is set to:

 $ cat ./Source/java/manifest.txt Class-Path: vtk.jar 

For information, if I change it to:

 $ cat ./Source/java/manifest.txt Class-Path: /usr/share/java/vtk.jar 

This gives a slightly different error:

 $ jar -i /tmp/vtk-dicom/bin/lib/vtkdicom.jar java.io.FileNotFoundException: /tmp/vtk-dicom/bin/lib/usr/share/java/vtk.jar (No such file or directory) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:215) at java.util.zip.ZipFile.<init>(ZipFile.java:145) at java.util.jar.JarFile.<init>(JarFile.java:154) at java.util.jar.JarFile.<init>(JarFile.java:91) at sun.tools.jar.Main.getJarPath(Main.java:1052) at sun.tools.jar.Main.getJarPath(Main.java:1068) at sun.tools.jar.Main.genIndex(Main.java:1084) at sun.tools.jar.Main.run(Main.java:269) at sun.tools.jar.Main.main(Main.java:1177) 

For reference:

 $ java -version java version "1.7.0_75" OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-2) OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode) 
+6
source share
2 answers

I did not find any documentation on this, but it seems to work if you provide other banks after the main bank:

 jar -i main.jar other.jar 

In your example:

 cd /tmp/vtk-dicom/bin/lib/ jar -i vtkdicom.jar /usr/share/java/vtk.jar 

Other jar files are not modified. The manifest does not require any changes.

Edit:

The generated INDEX.LIST file contains the full path you specified for "main.jar", so I first changed my example to "cd" in the directory. Otherwise, the jar file may not work after installing it in the final location.

Alternatively, "jar -i" can be run in a file after it is installed.

+1
source

First you need to specify in the MANIFEST Class-Path file for this JAR. The option I have is only to create an INDEX.LIST file that optimizes class loading.

So you need to insert your MANIFEST all the way into the JAR.

-1
source

Source: https://habr.com/ru/post/985843/


All Articles