Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sphinx-data doesn't work in modular Java apps #86

Open
Thorn1089 opened this issue Nov 27, 2018 · 3 comments
Open

sphinx-data doesn't work in modular Java apps #86

Thorn1089 opened this issue Nov 27, 2018 · 3 comments

Comments

@Thorn1089
Copy link

Because of changes made to how Class.getResource(String) works in Java 9 and above, simply including the sphinx-data JAR does not work to load the English acoustic model, dictionary, etc.

The problem is here:

public static URL resourceToURL(String location) throws MalformedURLException {
    Matcher jarMatcher = jarPattern.matcher(location);
    if (jarMatcher.matches()) {
      String resourceName = jarMatcher.group(1);
      return ConfigurationManagerUtils.class.getResource(resourceName);
    } else {
      if (location.indexOf(58) == -1) {
        location = "file:" + location;
      }

      return new URL(location);
    }
  }

Using a location such as resource:/edu/cmu/sphinx/models/en-us/en-us will no longer work. This is because Class.getResource will delegate to the classloader and pass the module name (in this case derived from the JAR file as "sphinx.core"). The problem is that the resources are in a different JAR, which gets the automatic module name "sphinx.data". Since the classloader will only look within the "sphinx.core" module, it won't find the resources from "sphinx.data."

@FriedaSmith
Copy link

@TomRK1089 Hello. Have you solved the problem? And how to solve it?

@Thorn1089
Copy link
Author

I had to copy the data files out of the JAR, repackage them in my own JAR, and extract them to the filesystem at startup. There was no simple workaround.

@FriedaSmith
Copy link

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants