0

我正在为一个新的团队/项目评估 install4j。该计划是用一个 install4j 安装程序替换一组特定于其平台的本地安装程序。我为团队构建的输出创建了一个简单的安装程序。Install4j 使用简单的安装程序做得很好,它将构建的输出放入自解压文件中,并在执行时将其放入目录中。

但是,当我尝试解压缩和解压缩嵌入在构建输出中的文件时,它会失败,但出现以下异常。

install4j 不能“开箱即用”处理 gzip 的 tar 文件吗?我需要为此编写自定义代码吗?或者它看起来像其他类型的错误?我检查了一下,我可以自己从命令行将文件解压缩并解压到我指定的目录中。

这是我需要在我的 MySQL、Tomcat 等安装程序中处理多个工件的事情。

java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:131)
    at java.util.zip.ZipFile.<init>(ZipFile.java:148)
    at com.install4j.runtime.beans.actions.files.AbstractExtractZipFileAction.getMaxProgress(Unknown Source)
    at com.install4j.runtime.beans.actions.files.AbstractExtractZipFileAction.extractZip(Unknown Source)
    at com.install4j.runtime.beans.actions.files.AbstractExtractZipFileAction.execute(Unknown Source)
    at com.install4j.runtime.beans.actions.SystemInstallOrUninstallAction.install(Unknown Source)
    at com.install4j.runtime.installer.InstallerContextImpl.performActionInt(Unknown Source)
    at com.install4j.runtime.installer.ContextImpl.performAction(Unknown Source)
    at com.install4j.runtime.installer.controller.Controller.executeActions(Unknown Source)
    at com.install4j.runtime.installer.controller.Controller.handleCommand(Unknown Source)
    at com.install4j.runtime.installer.controller.Controller.start(Unknown Source)
    at com.install4j.runtime.installer.Installer.runInProcess(Unknown Source)
    at com.install4j.runtime.installer.Installer.main(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
    at com.install4j.runtime.launcher.Launcher.main(Unknown Source)
4

2 回答 2

2

这最终并没有我想象的那么难。我在这篇文章中找到了一段有帮助的 JAVA 代码。

所以下面是我最终添加到“运行脚本”操作的代码。为正在安装的平台确定合适的 mysql tar 文件还不够聪明,但这只是一个开始。

import java.io.*;
import java.util.zip.*;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;

File tgzFile = new File(context.getInstallationDirectory(), "mysql/mysql-5.5.17-linux2.6-i686.tar.gz");

// Create the Tar input stream.
FileInputStream fin = new FileInputStream(tgzFile);
GZIPInputStream gin = new GZIPInputStream(fin);
TarInputStream tin = new TarInputStream(gin);

String outputDirectory = "mysql";

// Create the destination directory.
File outputDir = new File(outputDirectory);
outputDir.mkdir();

// Extract files.
TarEntry tarEntry = tin.getNextEntry();
while (tarEntry != null) {
    File destPath = new File(context.getInstallationDirectory(), outputDirectory + File.separator + tarEntry.getName());

    if (tarEntry.isDirectory()) {
        destPath.mkdirs();
    } else {
        // If the parent directory of a file doesn't exist, create it.
        if (!destPath.getParentFile().exists())
            destPath.getParentFile().mkdirs();

        FileOutputStream fout = new FileOutputStream(destPath);
        tin.copyEntryContents(fout);
        fout.close();
    // Presserve the last modified date of the tar'd files.
        destPath.setLastModified(tarEntry.getModTime().getTime());
    }
    tarEntry = tin.getNextEntry();
}
tin.close();

return true;
于 2012-02-08T14:45:56.483 回答
0

install4j 中的 ZIP 操作目前不适用于 gzip 压缩的 tar 文件,仅适用于 ZIP 文件。

于 2012-02-08T09:22:37.310 回答