本文介绍了TrueZip:NoClassDefFoundError(但仅适用于关机钩子?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用PhantomJS的项目.有一个可以自动安装的插件:

I have a project using PhantomJS. There is this plugin that will install it automatically:

      <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

添加这些内容(根据此线程):

Adding these (according to 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>

没有帮助(我收到相同的错误消息).

does not help (I get the same error message).

但是:二进制文件确实已下载并解压缩.系统属性被设置.依赖于此工作的测试可以完美运行.

However:The binary does gets downloaded and unzipped. The system property gets set. The tests that depend on this working run perfectly.

$ 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

...因此仅包含一个版本.

... so only one version is included.

推荐答案

我对PhantomJS不太了解,但是正如您所知,异常是由关闭挂钩抛出的.该挂钩是一个安全网,可通过TrueZIP提交对归档文件的所有未决更改.您可以在JVM终止之前调用de.schlichtherle.truezip.file.TVFS.umount()轻松地将其删除.请将该调用包装在finally块中,以确保即使应用程序以Throwable终止,该调用也会被调用.

I don't know much about PhantomJS, but as you figured the exception is thrown by a shutdown hook. This hook is a safety net which commits any pending changes to archive files by TrueZIP. You can easily remove it by calling de.schlichtherle.truezip.file.TVFS.umount() just before the JVM terminates. Please wrap the call in a finally-block to ensure it gets called even if the application terminates with a Throwable.

这篇关于TrueZip:NoClassDefFoundError(但仅适用于关机钩子?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:25