错误:jar执行中的noclassdeffounderror

时间:2012-12-20 21:45:27

标签: spring jar manifest executable-jar

我正在使用swing和spring为某些东西创建桌面应用程序。一切都很顺利但是当我使用eclipse JUNO创建jar时,我在cmd上尝试将其作为 java -jar myjar.jar 运行时遇到此错误。我不知道问题出在哪里,有什么帮助吗?

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
        at efact.alfa1lab.nazca.jframe.NazcaLogin.<init>(NazcaLogin.java:145)
        at efact.alfa1lab.nazca.jframe.NazcaLogin$1.run(NazcaLogin.java:97)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 16 more

这是我的文件夹结构

 - myclasses
 - images
 - lib
 - META-INF
 + MANIFEST.MF
   - applicationContext.xml
 - build.xml

这是我的 MANIFEST.MF 包含所有弹簧罐,包括: spring-context-support-3.2.0.M1.jar spring-context -3.2.0.M1.jar

Manifest-Version: 1.0
Class-Path: lib/swingx-1.6.1.jar lib/spring-aop-3.2.0.M1.jar lib/spring-context-support-3.2.0.M1.jar lib/spring-context-3.2.0.M1.jar
  lib/javadbf-0.4.0.jar lib/log4j-1.2.16.jar lib/spring-asm-3.2.0.M1.jar lib/spring-beans-3.2.0.M1.jar  
  lib/spring-core-3.2.0.M1.jar lib/spring-expression-3.2.0.M1.jar lib/spring-orm-3.2.0.M1.jar
  lib/spring-oxm-3.2.0.M1.jar lib/spring-test-3.2.0.M1.jar lib/spring-tx-3.2.0.M1.jar lib/spring-web-3.2.0.M1.jar
  lib/spring-webmvc-3.0.5.RELEASE.jar lib/spring-webmvc-3.2.0.M1.jar lib/spring-ws-1.5.9-all.jar lib/troughoasis.jar 
  lib/commons-lang-2.3.jar lib/commons-logging-1.1.1.jar lib/concar.jar lib/ini4j-0.5.2-SNAPSHOT.jar
Main-Class: com.mycompany.MainClass

1 个答案:

答案 0 :(得分:0)

Class-Path中的MANIFEST.MF指令无效。我建议您将One-JAR与Ant或Maven结合使用,将您的应用程序及其所有依赖项打包到一个JAR中。我一直在使用这种方法让上帝知道多久 - 完美无缺。