Exception in thread “main“ java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSONObject

Exception in thread "main" java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSONObject

报错:

C:\Users\li\Desktop\java\upload\upload_jar>java -jar upload-1.0-SNAPSHOT.jar

......

Exception in thread "main" java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSONObject

        at com.zd.util.Upload.main(Upload.java:35)

Caused by: java.lang.ClassNotFoundException: com.alibaba.fastjson.JSONObject

        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)

        ... 1 more

过程:

在将java maven项目打成jar包并通过java -jar xxx.jar命令运行时报错

解决办法:

首先通过压缩软件编辑jar包中的MANIFEST.MF文件,添加Class-path配置项目(见图1)将程序需要的jar包写到里边,用空格隔开,然后将程序需要的jar包放到该jar包的同级目录下(见图2)

图1:

图2:

Exception in thread “main“ java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSONObject_第1张图片

你可能感兴趣的:(java,java,jar)