【问题标题】:Java - Jar could not find included libraries and main classJava - Jar 找不到包含的库和主类
【发布时间】:2011-09-28 15:16:50
【问题描述】:

我目前正在尝试制作一个包含我所有库的 Jar。我所做的,我创建了这样的文件夹:

eancopy (which contain all my classes)
lib (containing all my libraries : mongo, jedis...)
META-INF/MANIFEST.MF

我的主类名为process(在包 eancopy 中)

我的清单是这样的:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Class-Path: lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Main-Class: eancopy.process

我已经用这个命令生成了 JAR:

jar cvmf META-INF/MANIFEST.MF EANcopy.jar eancopy/*.class lib/*.jar

我的问题:当通过java -jar EANcopy.jar 执行 JAR 时,它在我生成 JAR 的地方执行但在另一个地方我有消息时工作:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/DBObject
Caused by: java.lang.ClassNotFoundException: com.mongodb.DBObject
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: eancopy.process. Program will exit.

有什么想法吗?谢谢

【问题讨论】:

  • 你知道如何接受答案吗?

标签: java jar executable-jar


【解决方案1】:

这个异常告诉你问题的原因:

线程“main”中的异常 java.lang.NoClassDefFoundError: com/mongodb/DBObject

您没有在CLASSPATH 环境变量中指定这些库lib\commons-pool-1.5.6.jar lib\jedis-2.0.0.jar lib\mongo-2.6.3.jar,因此在其他地方运行时它会失败。

【讨论】:

  • 它在 MANIFEST -> Class-Path 中指定,为了兼容性我不喜欢使用 CLASSPATH 环境变量
  • 是的,但是所有这些罐子都包含在EANCopy.jar中吗?
猜你喜欢
  • 2015-05-17
  • 2021-10-02
  • 2021-06-06
  • 2023-03-29
  • 2018-08-21
  • 1970-01-01
  • 2020-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多