简体   繁体   English

Java Linux服务器:虽然在类路径中存在jar,但找不到类异常

[英]java linux server: class not found exception though jar in classpath

Im running a Java application on an Amazon EC2 instance which is a linux server. 我在作为Linux服务器的Amazon EC2实例上运行Java应用程序。 I included a json jar in the build path and I checked the class path and it's there. 我在构建路径中包含一个json jar,并检查了类路径,它就在那里。 When I import the class 当我导入课程时

import org.json.JSONException;
import org.json.JSONObject;

I dont get any compilation errors, but when I execute my app I get the ClassNotFoundException. 我没有得到任何编译错误,但是当我执行我的应用程序时,我得到了ClassNotFoundException。

Exception in thread "Thread-1" java.lang.NoClassDefFoundError: org/json/JSONException
at Group.run(Group.java:62)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Does anybody know how to fix it? 有人知道如何解决吗? I have tried to fix this for weeks now, I'm really frustrated! 我已经尝试修复了几个星期,我真的很沮丧!

I think it may be the environment setting problem. 我认为这可能是环境问题。

Try to edit ~/.bash_profile and append the CLASSPATH value like: 尝试编辑~/.bash_profile并附加CLASSPATH值,例如:

CLASSPATH=$CLASSPATH:/your/jar/folder/
export CLASSPATH

Then using following cmd to make the setting work: 然后使用以下cmd进行设置:

source ~/.bash_profile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM