Home > Software engineering >  How to recreate JDK tar.gz file after added a certificate
How to recreate JDK tar.gz file after added a certificate

Time:11-11

My organization requires all JDK to include a specific certificate.

I therefore followed these steps:

  1. downloaded the JDK as jdk-17-linux-x64.tar.gz (170M)
  2. unzip jdk-17-linux-x64.tar.gz
  3. Added our certificate using keytool
  4. created a new tarball jdk-17-linux-x64.tar.gz from the extracted contents (300M)

I then uploaded the new tarball to our Jenkins server, but I receive the following error:

    ERROR: Failed to download https://xxxx/jdk-17-linux-x64.tar.gz from agent; will retry from master
java.io.IOException: incorrect header check
    at com.jcraft.jzlib.InflaterInputStream.read(InflaterInputStream.java:112)
    at org.apache.commons.compress.utils.IOUtils.readFully(IOUtils.java:168)
    at org.apache.commons.compress.utils.IOUtils.readFully(IOUtils.java:142)
    at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.readRecord(TarArchiveInputStream.java:459)
    at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getRecord(TarArchiveInputStream.java:428)
    at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:305)
    at hudson.FilePath.readFromTar(FilePath.java:2582)
Caused: java.io.IOException: Failed to extract input stream
    at hudson.FilePath.readFromTar(FilePath.java:2608)
    at hudson.FilePath.access$500(FilePath.java:211)
    at hudson.FilePath$Unpack.invoke(FilePath.java:954)

I realized the new tar.gz I created is 300M in size, much larger than the 170M of the original tar ball.

Can someone please let me know how to recreate a proper JDK tarball? Maybe I should use a specific compression format?

CodePudding user response:

Based on the exception message, it looks like the file that Hudson is trying to extract is not a valid tar.gz file. As the regenerated file is roughly the same size as the uncompressed file tree, my guess is that you have missed out the compression step when creating the file; i.e. you have created an uncompressed TAR file.

A proper tar.gz file is a TAR file that has been compressed using gzip compression. You can create one like this:

$ tar -cfz my_jdk.tar.gz ....

or like this:

$ tar -cf my_jdk.tar ....
$ gzip my_jdk.tar

Refer to the manual entries for more details; e.g. read man tar and / or man gzip.

  • Related