0

I have included json-simple in my pom.xml for Maven:

<dependencies>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
</dependencies>

And I keep getting this error:

Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        ... 3 more

Here is my code:

JSONObject testLatest = new JSONObject(Files.readString(Paths.get("test-latest.json")));
JSONObject currentServer = new JSONObject(Files.readString(Paths.get("current-server.json")));

String latestStability = testLatest.getJSONObject("response").getString("stability");
String latestMD5 = testLatest.getJSONObject("response").getString("md5");

String currentMD5 = currentServer.getJSONObject("response").getString("md5");

if (latestStability.equals("stable") && !latestMD5.equals(currentMD5)) {
   replaceCurrentServer(true);
   return true;
}

Here is a screenshot of my module settings in InteliJ: Screenie

  • Did you add the dependency to your `module-info.java`? To add it just add `requires json.simple;` and leave an empty line underneath. – GregGott Jul 17 '22 at 08:16
  • I don't have one that I know of, should I create one or is it somewhere I just don't see? – CaptainBear Jul 17 '22 at 09:01
  • Normally this file should be in `src/main/java`. IntelliJ should create this file by default. I don't know if Eclipse creates `module-info.java` automatically. For a non-modular project, this file doesn't exist. [See image](https://openjfx.io/openjfx-docs/images/ide/intellij/modular/ide/idea01.png) – GregGott Jul 17 '22 at 09:08
  • I used the module manager in InteliJ and added it as a runtime dependency on top of it being a compile dependency. It is still not working. – CaptainBear Jul 17 '22 at 09:09
  • Can you please add your code and the `module-info.java` to your question? – GregGott Jul 17 '22 at 09:14
  • No problem, just did. – CaptainBear Jul 17 '22 at 09:17

1 Answers1

0

I don't mean the module manager of IntelliJ.

If you add modules to your project you need a modular project. Such a project needs a class called module-info.java.

According to the openjfx documentation:

Add the module-info class, including the required modules javafx.controls and javafx.fxml. Since FXML uses reflection to access the controller in the module, this has to be opened to javafx.fxml. Finally, export the package org.openjfx.

See image

In your case the module-info.java file should look similar to this (maybe some differences):

module com.example.project {
    requires javafx.controls;
    requires javafx.fxml;
    requires json.simple;
    requires javafx.graphics;

    opens com.example.project to javafx.fxml;
    exports com.example.project;
}

After that, your code should work.

GregGott
  • 95
  • 9
  • I added the module-info.java file given what you sent me (replacing the module name with `net.capbear.serverjarmanager`), and added org.openjfk to my dependencies and plugins in pom.xml, and it still isn't working. Did I do it properly? – CaptainBear Jul 17 '22 at 09:45