stanfordnlp/CoreNLP · warning

Could not load class in jar:

Error message

Could not load class in jar: 

What it means

While scanning jars for classes with @Option annotations, getVisibleClasses() calls Class.forName() on each candidate class name. If the class cannot be found by the system class loader (ClassNotFoundException), it logs 'Could not load class in jar: <jar> at path: <class>' and skips it. Scanning continues; the class is just not considered.

Solutions

  1. Add the jar containing the missing class to the system classpath
  2. Ignore the warning if the skipped class has no @Option annotations you need
  3. Remove broken/stale jars from the scanned directory
  4. Enable debug logging to see which class names are skipped and why
Defensive patterns

Strategy: fallback

Validate before calling

// pre-check a jar's entries resolve before scanning
try (JarFile jf = new JarFile(jarFile)) {
    jf.stream().map(e -> e.getName())
     .filter(n -> n.endsWith(".class"))
     .forEach(n -> {
         String cn = n.replace('/', '.').replaceAll("\\.class$", "");
         try { Class.forName(cn, false, ClassLoader.getSystemClassLoader()); }
         catch (ClassNotFoundException ex) { /* will be skipped by parser */ }
     });
}

Prevention

When it happens

Trigger: Invoking ArgumentParser fillOptions/bootstrapMap with a jar directory scan (e.g. 'properties' or class discovery mode) where a jar contains class entries whose names do not resolve against the system class loader - typically classes with external dependencies, multi-release jar entries, or non-class resources misnamed as .class.

Common situations: Pointing the scan at an arbitrary directory of jars; jars containing optional provider classes (JDBC drivers, service loaders) not on the classpath; old jars compiled against removed APIs.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/a0557037ec43ec42. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/ArgumentParser.java:260

        // --Case: Jar
        try (JarFile jar = new JarFile(f)) {
          Enumeration<JarEntry> e = jar.entries();
          while (e.hasMoreElements()) {
            //(for each jar file element)
            JarEntry jarEntry = e.nextElement();
            String clazz = jarEntry.getName();
            if (clazz.matches(".*class$")) {
              //(if it's a class)
              clazz = clazz.substring(0, clazz.length() - 6)
                  .replaceAll("/", ".");
              //(add it)
              try {
                classes.add(
                    Class.forName(clazz,
                        false,
                        ClassLoader.getSystemClassLoader()));
              } catch (ClassNotFoundException ex) {
                warn("Could not load class in jar: " + f + " at path: " + clazz);
              } catch (NoClassDefFoundError ex) {
                debug("Could not scan class: " + clazz + " (in jar: " + f + ')');
              }
            }
          }
        } catch (IOException e) {
          warn("Could not open jar file: " + f + "(are you sure the file exists?)");
        }
      } else {
        //case: ignored jar
      }
    }

    return classes.toArray(new Class<?>[classes.size()]);
  }

  /**
   * Get all the declared fields of this class and all super classes.

View on GitHub (pinned to 1b7edd19c4)