TrueZip: NoClassDefFoundError (but for shutdown hook only?)

こ雲淡風輕ζ 提交于 2019-12-24 03:12:25

问题


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>

And I get this error:

[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.

Also,

$ 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.


回答1:


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.




回答2:


If you execute it via java -jar or your maven plugin calls a goal "outside" of provided scope, set the scope of the dependencies to compile.



来源:https://stackoverflow.com/questions/31267536/truezip-noclassdeffounderror-but-for-shutdown-hook-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!