调用cp_rp方法时抛出TrueZip异常

时间:2011-06-17 16:42:38

标签: java truezip

我有一个非常简单的程序,我正在尝试将目录添加到新的zip文件中。代码:

public class Encrypt {
    public static void main(String[] args) {
        TFile srcFile = new TFile(args[0]);
        TFile destFile = new TFile("/home/myuser/archive.zip");
        try {
            TFile.umount();
        } catch (FsSyncException e1) {
            e1.printStackTrace();
        }

        try {
            if (destFile.isArchive() || destFile.isDirectory())
                 destFile = new TFile(destFile, srcFile.getName());
            srcFile.cp_rp(destFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            TFile.umount();
        } catch (FsSyncException e) {
            e.printStackTrace();
        }
    }
}

这几乎是来自here的代码。 例外:

Jun 17, 2011 12:10:26 PM de.schlichtherle.truezip.fs.sl.FsDriverLocator$Boot <clinit>
WARNING: No provider available for class de.schlichtherle.truezip.fs.spi.FsDriverService
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.util.ServiceConfigurationError: file (unknown file system scheme - check run time class path configuration)
        at de.schlichtherle.truezip.file.TArchiveDetector.newController(TArchiveDetector.java:341)
        at de.schlichtherle.truezip.fs.FsDefaultManager.getController(FsDefaultManager.java:75)
        at de.schlichtherle.truezip.fs.FsDefaultManager.getController(FsDefaultManager.java:65)
        at de.schlichtherle.truezip.fs.FsFailSafeManager.getController(FsFailSafeManager.java:59)
        at de.schlichtherle.truezip.file.TBIO.getInputSocket(TBIO.java:291)
        at de.schlichtherle.truezip.file.TBIO.cp0(TBIO.java:229)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:193)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r0(TBIO.java:183)
        at de.schlichtherle.truezip.file.TBIO.cp_r(TBIO.java:154)
        at de.schlichtherle.truezip.file.TFile.cp_rp(TFile.java:3161)
        at Encrypt.main(Encrypt.java:38)
        ... 5 more

我无法在项目页面或其他页面上找到与此异常相关的任何内容。谁看过这个吗?我正在使用TrueZip 7.1.4。

3 个答案:

答案 0 :(得分:2)

是的,您要访问的文件系统驱动程序模块存在运行时依赖性。

E.g。如果要访问ZIP文件,则需要在运行时类路径上具有模块TrueZIP驱动程序ZIP(truezip-driver-zip)和TrueZIP驱动程序文件(truezip-driver-file)的JAR。

答案 1 :(得分:0)

问题是项目缺少JAR依赖:truezip-driver-file-jse7-7.2-beta-3.jar。你可以从here获得它。找到所需的所有文件非常困难。

答案 2 :(得分:0)

如果您正在使用Maven,则可以将以下dependencies添加到pom.xml文件中,例如

  <dependencies>
    <dependency>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>truezip-maven-plugin</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>de.schlichtherle.truezip</groupId>
      <artifactId>truezip-driver-file</artifactId>
      <version>7.7.10</version>
    </dependency>
    <dependency>
      <groupId>de.schlichtherle.truezip</groupId>
      <artifactId>truezip-file</artifactId>
      <version>7.7.10</version>
    </dependency>
    <dependency>
      <groupId>de.schlichtherle.truezip</groupId>
      <artifactId>truezip-kernel</artifactId>
      <version>7.7.10</version>
    </dependency>
    <dependency>
      <groupId>de.schlichtherle.truezip</groupId>
      <artifactId>truezip-driver-zip</artifactId>
      <version>7.7.10</version>
    </dependency>
  </dependencies>

然后运行mvn clean install它应该可以。

相关问题