0

I create a json File and i wanna launch the Software on my Server but probably I get this error

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
    at me.discord.JSON.<init>(JSON.java:27)
    at me.discord.Main.main(Main.java:35)
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 2 more

I dont know how i get a File at Linux on Windows its worked

String decodedPath = "/root/";
String content;
File db = new File(decodedPath + "/Database.json");
JSONObject json;
public JSON(){
    try{
        content = new String(Files.readAllBytes(Paths.get(db.toURI())), "UTF-8");
    }catch (Exception e) {

    }
    onLoad();
    Main.jsonMan = this;
    json = new JSONObject(content);
}
  • 1
    The problem is your CLASSPATH. You're importing `org.json.JSONObject`, but your JVM cannot find this runtime dependency. Look here: [How do I resolve ClassNotFoundException?](https://stackoverflow.com/questions/17408769/how-do-i-resolve-classnotfoundexception) – FoggyDay Jun 14 '20 at 17:29

2 Answers2

0

Seems like JSON jar is not in classpath.

Try adding below dependency to you project and confirm that it is available after deployment too.

<dependency>
   <groupId>org.json</groupId>
   <artifactId>json</artifactId>
   <version>20080701</version>
</dependency>
0

You need to get JSON jar file. You can get the dependency details from following link

https://mvnrepository.com/artifact/org.json/json

<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20200518</version>
</dependency>

If you are familiar with maven you can resolve dependency by updating the pom.xml using above dependency tag, else download the jar file from following location:

https://mvnrepository.com/artifact/org.json/json/20180130

After downloading the jar file, save it in any folder of your choice, let's say /lib/json-20180130.jar

After that execute the following commands to compile and run the code.

export CLASSPATH=.:/usr/jar/json-20180130.jar

//Sample.java is name of your file.
javac Sample.java

java -cp "/lib/json-20180130.jar" Sample
Naresh Chaurasia
  • 419
  • 5
  • 21
  • Still get the error and i put the import the dependency – Emzudemil Jun 15 '20 at 11:45
  • Can you share your code and jars. I will run on my Linux box. Do share the entire java code with import statements and any other relevant information. – Naresh Chaurasia Jun 15 '20 at 15:37
  • https://mega.nz/file/BltQhaDL#f6Tf71uVJqRnj6nZHnMx0rLlJuM_vRzZ9IDSX-dqVq0 The Projekt i make a few things unloaded that you dont get a Error because you have a Missing Key – Emzudemil Jun 16 '20 at 13:43