【发布时间】:2013-04-01 08:18:10
【问题描述】:
使用 ant 构建 JSGFDemo 时,一切正常。运行 JSGFDemo.jar 构建工件没有任何错误。但是,当使用 eclipse 中导入的源文件夹,并将 lib/ 目录中的 jars 添加到构建路径时,程序错误并显示以下消息:
Problem configuring recognizerProperty exception component:'jsgfGrammar' property:'grammarLocation' - Can't locate resource:/edu/cmu/sphinx/demo/jsapi/jsgf/
edu.cmu.sphinx.util.props.InternalConfigurationException: Can't locate resource:/edu/cmu/sphinx/demo/jsapi/jsgf/
由于某种原因,在 ConfigurationManagerUtils.resourceToURL(String location) 中对 ConfigurationManagerUtils.class.getResource(resourceName); 的调用似乎会为 location = "resource:/edu/cmu/sphinx/demo/jsapi/jsgf/" 返回不同的结果。 (null,或有效的 URL 对象)
作为旁注,我认为 getResource("/path/to/a/dir/not/file/");解析为 jar 内的路径时无效。
我已经为此苦苦挣扎了一段时间,看不出我做错了什么。
【问题讨论】:
-
缺少资源的唯一原因是缺少资源。此错误意味着您的类路径中没有相应的路径。可能您对包的命名不同,并且没有更改 config.xml 文件中的路径。您需要提供更多关于您的项目布局、项目的文件结构等信息,以便获得更有意义的答案。
-
@NikolayShmyrev 据我所知,这些罐子具有相同的文件结构。如果需要,请查看它们:docs.google.com/file/d/0B4ayCXFZPsx8aU5DeGRXb1VpNm8/edit 但是,如果我附加某些特定文件的文件名,则不会出现错误,例如资源:/edu/cmu/sphinx/demo/jsapi/jsgf/commands.gram,但显然这在 sphinx 尝试引用资源时不起作用:/edu/cmu/sphinx/demo/jsapi/jsgf/command.gram/command.gram