TrueZip:NoClassDefFoundError(但仅限于shutdown hook?)

时间:2015-07-07 11:38:35

标签: java maven phantomjs truezip

我有一个使用PhantomJS的项目。有这个插件会自动安装它:

      <plugin>
        <groupId>com.github.klieber</groupId>
        <artifactId>phantomjs-maven-plugin</artifactId>
        <version>0.2.1</version>
        <executions>
          <execution>
            <goals>
              <goal>install</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <version>1.9.2</version>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <configuration>
          <systemPropertyVariables>
            <phantomjs.binary>${phantomjs.binary}</phantomjs.binary>
          </systemPropertyVariables>
        </configuration>
      </plugin>

我收到了这个错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.665 s
[INFO] Finished at: 2015-07-07T13:27:39+02:00
[INFO] Final Memory: 31M/175M
[INFO] ------------------------------------------------------------------------
java.lang.NoClassDefFoundError: de/schlichtherle/truezip/fs/FsSyncOptions
    at de.schlichtherle.truezip.fs.FsSyncShutdownHook$Hook.run(FsSyncShutdownHook.java:93)
Caused by: java.lang.ClassNotFoundException: de.schlichtherle.truezip.fs.FsSyncOptions
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
    ... 1 more

添加这些(根据this thread):

<dependency>
  <!-- For the PhantomJS install plugin -->
  <groupId>de.schlichtherle.truezip</groupId>
  <artifactId>truezip-driver-file</artifactId>
  <version>7.7.9</version>
</dependency>
<dependency>
  <!-- For the PhantomJS install plugin -->
  <groupId>de.schlichtherle.truezip</groupId>
  <artifactId>truezip-kernel</artifactId>
  <version>7.7.9</version>
</dependency>
<dependency>
  <!-- For the PhantomJS install plugin -->
  <groupId>de.schlichtherle.truezip</groupId>
  <artifactId>truezip-driver-zip</artifactId>
  <version>7.7.9</version>
</dependency>

无效(我收到相同的错误消息)。

然而: 二进制文件会被下载并解压缩。系统属性已设置。依赖于此工作的测试运行完美。

此外,

$ mvn dependency:tree | grep truezip
[INFO] +- de.schlichtherle.truezip:truezip-driver-file:jar:7.7.9:compile
[INFO] +- de.schlichtherle.truezip:truezip-kernel:jar:7.7.9:compile
[INFO] +- de.schlichtherle.truezip:truezip-driver-zip:jar:7.7.9:compile
[INFO] |  +- de.schlichtherle.truezip:truezip-swing:jar:7.7.9:compile

...所以只包含一个版本。

3 个答案:

答案 0 :(得分:1)

我对PhantomJS了解不多,但是当你想到一个关闭钩子抛出异常时。此挂钩是一个安全网,它通过TrueZIP提交对存档文件的任何挂起更改。您可以在JVM终止之前调用de.schlichtherle.truezip.file.TVFS.umount()轻松删除它。请将调用包装在finally - 块中,以确保即使应用程序以Throwable终止也会调用它。

答案 1 :(得分:0)

如果您通过java -jar执行它,或者您的maven插件调用提供范围的“外部”目标,请将依赖关系的范围设置为compile

答案 2 :(得分:0)

我能够通过将Java版本从IBM Java 1.7更改为IBM Java 1.8(ibm_sdk_8.0.3.0)或Oracle Java 1.8(jdk_1.8.0.91_64)来解决此问题。您可以通过在终端或命令提示符下键入java -version来检查Java版本。操作系统= Windows 10