简体   繁体   中英

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. I included a json jar in the build path and I checked the class path and it's there. 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.

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:

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

Then using following cmd to make the setting work:

source ~/.bash_profile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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