执行JAR时,得到ExceptionInInitializerError: version.properties not found
我一直在 Eclipse 中编写一个小项目,该项目在 IDE 中完美运行。然后我通过 Eclipse 构建了一个可运行的 .jar 文件(它应该包含 jar 本身内的每个依赖库)。
我在我的项目中使用 3 个库:
- derby.jar
- qtjambi-4.7.1.jar
- qtjambi-win32-msvc2008-4.7.1.jar
然后我使用这个命令(在 Windows 中):
java -jar prova.jar
我得到这个:
Connected to database
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.ExceptionInInitializerError: version.properties not found!
at com.trolltech.qt.Utilities.<clinit>(Unknown Source)
at com.trolltech.qt.QtJambi_LibraryInitializer.<clinit>(Unknown Source)
at com.trolltech.qt.QtJambiObject.<clinit>(Unknown Source)
at WAAAGH.main(WAAAGH.java:52)
... 5 more
正如您所看到的,derby.jar 正在按预期工作(“连接到数据库”),但 Qt-Jambi 存在一个我无法理解的错误。有什么想法吗?
编辑: WAAAGH 是包含 main 方法的类,第 52 行包含:
QApplication.initialize(args);
I've been writing a small project in Eclipse which runs perfectly within the IDE. Then I've build a runnable .jar file through Eclipse (which should include every dependency library inside the jar itself).
I use 3 library in my project:
- derby.jar
- qtjambi-4.7.1.jar
- qtjambi-win32-msvc2008-4.7.1.jar
Then I use this command (in windows):
java -jar prova.jar
And I get this:
Connected to database
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.ExceptionInInitializerError: version.properties not found!
at com.trolltech.qt.Utilities.<clinit>(Unknown Source)
at com.trolltech.qt.QtJambi_LibraryInitializer.<clinit>(Unknown Source)
at com.trolltech.qt.QtJambiObject.<clinit>(Unknown Source)
at WAAAGH.main(WAAAGH.java:52)
... 5 more
As you can see the derby.jar is working as expected ("Connected to database"), but there's an error with Qt-Jambi that I can't understand. Any idea?
EDIT: WAAAGH is the class containing the main method, line 52 consists in:
QApplication.initialize(args);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
QtJambiObject
如何加载?您是否将其打包到您的prova.jar
中?缺少的文件version.properties
应该是顶层同一 jar 的一部分(而不是在任何子目录中)。看来您还没有将其打包到顶层的prova.jar
中。请参阅这个用于解释它是如何加载的。您最好在命令行上指定所有 jar 和主类:
replace ; with : 如果你在 *nix 上运行
How is
QtJambiObject
getting loaded? Have you packeged it inside yourprova.jar
? The missing fileversion.properties
should be part of the same jar at top level (not in any subdir). It seems you have not packaged it insideprova.jar
at top level. See this for explanation of how it is loaded.You might be better off specifying all jars and main class on command line:
replace ; with : if you are running on *nix
FWIW version.properties 的位置最近已更改为位于捆绑包 com/trolltech/qt/version.properties 的包命名空间内。旧位置是一个糟糕的设计选择,现已得到纠正。问题是,如果您的类路径中还有另一个 JAR,并且该 JAR 也具有顶级文件,则 ClassLoader 有权认为包含该文件的 JAR 对于该包具有权威性,并且不需要在另一个 JAR 中搜索该文件。包是 Java 中的最小可部署单元,只有专业的类加载器(例如 OSGi 中使用的类加载器)才具有解决 Java 设计的这一部分的功能。
通常,您的顶级(应用程序 JAR)将位于列表中的第一个,我敢打赌,在该 JAR 中您有一个或多个文件,例如 /log4j.properties /commons-logging.properties 等...这是因为然后存在一个或多个文件屏蔽(隐藏)qtjambi-XYZjar 中的文件,使其在运行时不被看到。这就是为什么当您测试某个场景时问题可能不存在,但当您尝试另一个场景时(当您以某种方式更改 ClassPath 时),问题可能会出现。
我对该项目的承诺 http://qt.gitorious.org/qt-jambi/qtjambi-community/commit/f18ce5da3e30b43424bf94e49adf8c4cac0d9862 在代码中更好地解释了最近的更改,以使生活更美好。
永远不应该出现这样的情况:您必须将 version.properties 文件从 QtJambi 可再发行 JAR 复制到类路径的其他部分(例如您的情况下的顶级项目 prova.jar),这是一个已更正的错误为下一个版本。完全消除对该文件的需求是我的长期目标,我 80% 的人都支持这个目标,作为该工作的一部分,使多个本机 JAR 共存于同一个类路径中将大大简化部署和入门指南;以及让他们可以很好地使用 OSGi 和 Eclipse。
然而,尚未发布包含此更改的版本,但我已经非常接近了(在 Qt 4.7.4 中这样做的 30 天内)。
开源插件警报:请考虑加入邮件列表 http://lists。 qt.nokia.com/pipermail/qt-jambi-interest/ 来自 http://lists.qt.nokia.com/mailman/listinfo 查看公告。
FWIW the location of version.properties has recently been changed to be inside the package namespace of the bundles com/trolltech/qt/version.properties. The old location was a poor design choice and that has now been corrected. The issue is that if you have another JAR in your classpath that also has a toplevel file then the ClassLoader is entitled to think that the JAR with that file is authorative for the package and it does not need to search another JAR for the file. A package is a minimum deployable unit in Java, only specialist ClassLoaders (such as those use in OSGi) have features to work around this part of the Java design.
Usually your toplevel (application JAR) will be first in the list and I bet in that JAR you have one or more files like /log4j.properties /commons-logging.properties etc... it is because one or more file exists it then masks (hides) the file in the qtjambi-X.Y.Z.jar from being seen at runtime. Which is why the problem might not exist when you test a certain scenario but then appear when you try another (when you changed ClassPath in some way).
My commit to the project at http://qt.gitorious.org/qt-jambi/qtjambi-community/commit/f18ce5da3e30b43424bf94e49adf8c4cac0d9862 better explains in code the very recent change to make life better.
It should never have been the case that you have to copy the version.properties file from the QtJambi redistributable JARs into some other part of the Class Path (like the toplevel project prova.jar in your case) this is a bug that has been corrected for the next release. It is the long term intention to remove the need for the file completely and I am 80% there with that goal, as part of that work making multiple native JARs co-exist in the same Class Path will greatly simplify deployment and getting started guides; as well as making them play with OSGi and Eclipse nicely out-the-box.
However no releases have been made yet to include this change but I am very close (within 30 days of doing so for Qt 4.7.4).
Open Source plug alert: Please consider joining the mailing list at http://lists.qt.nokia.com/pipermail/qt-jambi-interest/ from http://lists.qt.nokia.com/mailman/listinfo for announcements.