2012-02-07 82 views
0

我正在爲新團隊/項目評估install4j。計劃是用一個install4j安裝程序替換一組特定於自己平臺的自制安裝程序。我爲團隊構建的輸出創建了一個簡單的安裝程序。 Install4j使用簡單的安裝程序做了很好的工作,該安裝程序將構建的輸出轉換爲自解壓縮文件並在執行時將其放入目錄中。如何解壓縮並解壓嵌入在使用install4j構建的安裝程序中的文件?

但是,當我嘗試解壓並解壓嵌入在構建輸出中的文件時,它會失敗,並顯示下面的異常。

install4j無法處理gzip'd 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) 

回答

0

在install4j目前不gzip壓縮的tar文件的工作,只能用ZIP文件的ZIP行動。

+0

好吧,以便回答我現在必須編寫自定義代碼的問題。任何建議/提示/指向最有效的方式來做到這一點?我可以輕鬆使用「運行腳本」操作嗎?或者我需要寫一個擴展名?如果我需要寫一個擴展名,你能指點我的任何教程嗎? – Frank 2012-02-08 13:12:09

+0

今天我遇到了同樣的問題,它仍然不能用於6.0.4版本。也許這可能是下一個版本的改進之一?否則,我必須在Maven構建時解壓縮我的文件,但這不是預先解決的解決方法。 – Hardie82 2016-03-09 10:58:33

+0

我已將此添加到我們的問題跟蹤器中。 – 2016-03-09 11:40:09

2

這並沒有像我想的那樣艱難。我找到了this post中的一段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; 
+0

我在這個實現中發現了一個問題。它不處理GNU長文件名。因此,路徑長度超過99個字符的tar文件處理不當。仍在努力。 – Frank 2012-02-08 16:55:15

相關問題