如何在linux机器上导入jar文件
我正在尝试在 Linux 机器上运行 Java 程序,其中包括:
import javax.mail.*;
我已将 mail.jar
包含到 myjdk/lib
中。即使在编译时它也会显示错误,例如“
javax.mail does not exist
做什么?”
I am trying to run a Java program on Linux machine, that includes:
import javax.mail.*;
I have included mail.jar
into myjdk/lib
. Even on compiling it shows errors like
javax.mail does not exist
What to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 bash 上运行此命令
然后编译
On bash run this command
and then compile
检查你的类路径。确保它指向目录中的所有 JAR 文件。这应该通过 JAR 的直接路径或通配符来指定。
看一下有关设置类路径的页面: http ://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
Check your CLASSPATH. Make sure it points to all JAR files in the directory. This should be specified by either a direct path to the your JAR, or a wildcard.
Take a look at this page on setting the class path: http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html
根据您的评论,我假设您有一个脚本可以从“lib”目录中的文件构建类路径。
在这种情况下,最可能的问题是 Windows 使用分号(“;”)作为类路径分隔符,而 Linux 使用冒号(“:”)。
顺便说一句,我不知道在这两种环境下都有效的解决方案。通常的方法是为 Linux 创建“runme.sh”,为 Windows 创建“runme.bat”。
Based on your comments, I'm going to assume that you have a script to construct the classpath from the files in the "lib" directory.
In that case, the most likely problem is that Windows uses a semi-colon (";") as a classpath separator, while Linux uses a colon (":").
Offhand, I don't know of a solution that works in both environments. The usual approach is to create a "runme.sh" for Linux, and a "runme.bat" for Windows.
将所有 jar 文件和 .java 文件复制到同一文件夹中。
编译,
执行,
Copy all your jar files and .java files in same folder.
To compile,
To execute,