【发布时间】:2016-09-14 02:28:57
【问题描述】:
要使用 JAWS,需要在应用程序中指定 WordNet 数据库目录,如下所述:http://lyle.smu.edu/~tspell/jaws/。
System.setProperty("wordnet.database.dir", "resources/WordNet-3.0/dict/");
这在 IDE 中运行良好。但未编译为 .jar 文件。因此,需要 .jar 文件中 WordNet 目录的相对路径。已经尝试了各种方法。最后是:
String url = this.getClass().getClassLoader()
.getResource("resources/WordNet-3.0/dict/index.sense").toExternalForm();
url = url.substring(0, url.length() - 12);
从 .jar 文件中测试的结果:
jar:file:/C:/file/path/jar.jar!/resources/WordNet-3.0/dict/
认为这是解决方案,但运行 .jar 时仍然找不到目录,或者更确切地说是 index.sense。 index.sense 应该通过以下方式加载:
WordNetDatabase database = WordNetDatabase.getFileInstance();
它使用指定的目录。找到了几个线程,但没有任何建议有效。例如:
How to get the path of a running JAR file? How to get a path to a resource in a Java JAR file Loading a file relative to the executing jar file
【问题讨论】:
-
您好,我们也面临同样的问题,您能否通过发布解决方案或详细说明解决方案来帮助我们。提前致谢。
标签: java jar path jaws-wordnet