编译好但运行时NoClassDefFoundError [英] Compiled OK but NoClassDefFoundError when running

查看:265
本文介绍了编译好但运行时NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JavaMail API发送电子邮件。
我在自我提取二进制文件的主目录中安装了jdk 1.5。我在Ubintu 9.10

I'm trying to send an email using JavaMail API. I have jdk 1.5 installed in my home directory from self-extracting binary. I'm on Ubintu 9.10

我使用下一个命令编译程序:

I compile the program using the next command:

〜/ jdk1.5.0 _22 / bin / javac -classpath~ / jdk1.5.0_22 / jre / lib / javamail-1.4.3 / mail.jar:〜/ jdk1.5.0_22 / jre / lib / jaf-1.1.1 / activation.jar hw。 java

~/jdk1.5.0_22/bin/javac -classpath ~/jdk1.5.0_22/jre/lib/javamail-1.4.3/mail.jar:~/jdk1.5.0_22/jre/lib/jaf-1.1.1/activation.jar hw.java

它编译好了。如您所见,我已指定mail.jar和activation.jar的路径
现在我尝试使用下一个命令运行应用程序:

It compiles OK. As you can see I have specified the path to mail.jar and activation.jar Now I try to run the app using the next command:

〜/ jdk1.5.0_22 / bin / java -classpath~ / jdk1.5.0_22 / jre / lib / jaf-1.1.1 / activation.jar:〜/ jdk1.5.0_22 / jre / lib / javamail-1.4.3 / mail。罐:。 HelloWorldApp

~/jdk1.5.0_22/bin/java -classpath ~/jdk1.5.0_22/jre/lib/jaf-1.1.1/activation.jar:~/jdk1.5.0_22/jre/lib/javamail-1.4.3/mail.jar:. HelloWorldApp

我得到一个例外java.lang.NoClassDefFoundError:javax / mail / Address

I get an exception java.lang.NoClassDefFoundError: javax/mail/Address

为什么它能找到编译时的类,运行时不能这样做?
如何正确运行我的应用程序?

Why can it find classes when compiling and cannot do it when running? How to correctly run my app?

提前致谢

推荐答案

该类应来自您的 mail.jar 。我不确定你的类路径是否正确解析。代字号(〜)是一个shell函数,在发送到Java进程之前需要扩展。您是否尝试删除〜并替换为 / home / {whatever} ?我怀疑这是问题所在。

That class should come from your mail.jar. I'm not sure your classpath is being parsed properly. The tilde (~) is a shell function and needs expanding before being sent to the Java process. Have you tried removing the ~ and replacing with /home/{whatever} ? I suspect that's the issue.

这篇关于编译好但运行时NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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