简体   繁体   中英

LTI-Civil Project wierd error when exported to a JAR

Outline: 1. My project uses LTI-CIVIL to capture webcam. 2. In Eclipse, everything works fine. 3. As LTI_CIVIL uses native libraries to access hardware, I have opted to use JarClassLoader (info found here http://www.jdotsoft.com/JarClassLoader.php#download ) which allows for the native libraries to be unpacked into a temporary folder at runtime. Everything works great and I can even access the webcam capture stream until... I try to work with the Image handed in from the webcam which is of type com.lti.civil.NativeVideoFormat. The problem is that when run from the executable jar, it says that this class does not implement com.lti.civl.VideoFormat when it obviously does. I have even printed out the getClass() of the code running on eclipse and verified that the webcam Image is both of the same type. However, when I printout if the getClass() instanceof NativeVideoFormat, in the eclipse version this prints true, but in the jar version it prints false.

Interestingly, this problem has appeared before, but with no solution: https://forums.oracle.com/forums/thread.jspa?messageID=10637883&#10637883

Thanks for your help

You say that "it obviously does" implement that interface, but I think that the problem is that it actually doesn't. I think you have multiple "incarnations" of that interface type.

The real type of a class (or interface) at runtime depends is the identity of the Class object:

  • If clazz == clazz2 then they represent the same type. (The equals(Object) method on a Class tests the same condition ...)
  • Otherwise they don't, irrespective of the class names.

It would appear that your application's use of classloaders has resulted in one .class file being loaded twice in two different class loaders. I suspect that your JarClassLoader instance doesn't have the correct parent classloader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM