0

TileManager.class.getResourceAsStream("maps/Level_0.json") works fine if I compile everything, but when I put it in a jar, it returned Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonDeserializer

My code for loading the JSON file is:

    String src = "/maps/Level_0.json";
        // default StandardCharsets.UTF_8

        InputStream is = TileManager.class.getResourceAsStream(src);

        assert is != null;
        content = new BufferedReader(new InputStreamReader(is))
                .lines().collect(Collectors.joining("\n"));

        System.out.println(content);
        data = Converter.fromJsonString(content);

The location of Level_0.json is src/res/maps/Level_0.json and res is a source folder.

[x] I have imported all the libraries into the jar file.

  • *"[x] I have imported all the libraries into the jar file."* - The evidence suggests that you haven't done it the right way. Putting a JAR inside another JAR won't work with the standard Java classloaders. – Stephen C Sep 04 '22 at 05:06
  • I use intelliJ IDEA. in the project settings, I included the libraries and selected them in artifacts – Hackcraft_ Sep 04 '22 at 18:41
  • Also, the error is caused by ClassNotFoundException – Hackcraft_ Sep 04 '22 at 18:42
  • 1
    That is further evidence that what you did in `[x]` is not sufficient. I'm not familiar with Intellij, but you haven't said anything about how you are building the JAR. A normal JAR does NOT contain the external libraries. – Stephen C Sep 05 '22 at 00:12

0 Answers0