使用JAR,java.lang.NoClassDefFoundError:javax / mail / Store的Java错误 [英] Java error using JARs, java.lang.NoClassDefFoundError: javax/mail/Store

查看:131
本文介绍了使用JAR,java.lang.NoClassDefFoundError:javax / mail / Store的Java错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个使用Javamail的java应用程序,在编译它时效果很好。我想将它变成一个jar文件,以便它可以轻松移动并执行。问题是当我尝试从cmd行运行jar时出现此错误

I'm making a java application that uses Javamail, and it works great when I compile it. I want to make it into a jar file so it can be easily moved around and executed. The problem is I am getting this error when I try to run the jar from the cmd line

java -jar ActriveTray2.jar

java -jar ActriveTray2.jar

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Store
        at stockApp.init(stockApp.java:11)
        at ActiveTray.main(ActiveTray.java:31)
        Caused by: java.lang.ClassNotFoundException: javax.mail.Store
        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)

这是我的jar文件中的内容

Here's what's in my jar file


  • images / tray.gif

  • META-INF / MANIFEST.MF

  • ActiveTray.class

  • ActiveTray.java

  • config.class

  • config.java

  • GmailFetch.class

  • GmailFetch.java

  • stockApp $ 1.class

  • stockApp.class

  • stockApp.java

  • images/tray.gif
  • META-INF/MANIFEST.MF
  • ActiveTray.class
  • ActiveTray.java
  • config.class
  • config.java
  • GmailFetch.class
  • GmailFetch.java
  • stockApp$1.class
  • stockApp.class
  • stockApp.java

我认为问题是classpath,其中jar不知道javamail jar所在的位置。当我执行代码时,我的类路径设置正确(java ActiveTray2)它工作正常...帮助:(

I think the issue is classpath, where the jar doesn't know where the javamail jar lives. My classpath is set correctly when I execute the code (java ActiveTray2) it works fine... help :(

推荐答案

你需要将您依赖的jar添加到清单文件中,并将它们添加到您正在创建的jar中.java -jar将忽略您环境的类路径,设计。
来自java文档:

you need to add the jars you depend on to the manifest file, and also add them to the jar you are creating. java -jar will ignore your environment's classpath, by design. From the java docs:


-jar:当您使用此选项时,JAR文件是所有用户类的源,并忽略其他用户类路径设置。

-jar: When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

因此,您可以在清单文件中添加一行,如:

so, you can add a line to your manifest file like:

Class-Path: mail.jar

到您的清单文件。

这篇关于使用JAR,java.lang.NoClassDefFoundError:javax / mail / Store的Java错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆