ClassCastException in executable JAR not inside IDE
I have 开发者_开发百科a problem running my application outside Eclipse. It gives ClassCastException at the place where the application inside IDE does not. In particular, I output to the terminal the name of the instance I'm trying to cast and inside IDE it gives the correct type such as "NestedEngineImpl" whereas outside IDE it gives "EngineImpl" with the exception that EngineImpl cannot be cast to NestedEngineImpl. NestedEngineImple extends EngineImpl.The executable jar has been created using Eclipse' Export Runnable JAR file. The jar opens and runs until the point of exception.
Any advice will be greatly appreciated.
Check versions of your jars. Try this (replace "java/lang/Object.class" with appropriate path to your class):
ClassLoader.getSystemClassLoader().getSystemResource("java/lang/Object.class")
It will give you URL to your jar, which you can print out to check from where your class is coming).
Perhaps you are suffering from what we call Jar Hell
it is similar to DLL Hell
where you have a incorrect version of the JAR and you need to replace it with the correct one. This happens more frequently in large development environments where libraries are constantly being changed.
Thank all for the replies. I simply didn't specify the VM arguments when running the jar that were set in Eclipse.
精彩评论