Build 斯芬克斯语法定位可以';无法定位资源
使用ant构建JSGFDemo时,一切正常。运行JSGFDemo.jar构建工件不会出现任何错误。但是,当使用eclipse中导入的源文件夹并将lib/目录中的jar添加到构建路径时,程序会出现错误,并显示以下消息:Build 斯芬克斯语法定位可以';无法定位资源,build,cmusphinx,sphinx4,Build,Cmusphinx,Sphinx4,使用ant构建JSGFDemo时,一切正常。运行JSGFDemo.jar构建工件不会出现任何错误。但是,当使用eclipse中导入的源文件夹并将lib/目录中的jar添加到构建路径时,程序会出现错误,并显示以下消息: Problem configuring recognizerProperty exception component:'jsgfGrammar' property:'grammarLocation' - Can't locate resource:/edu/cmu/sphinx/d
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.class.getResource(resourceName)ConfigurationManagerUtils.resourceToURL(字符串位置)
中的code>似乎为location=“resource:/edu/cmu/sphinx/demo/jsapi/jsgf/”返回不同的结果。(空,或有效的URL对象)
作为旁注,我认为getResource(“/path/to/a/dir/not/file/”;解析为jar内的路径时无效
我已经为此绞尽脑汁一段时间了,看不出我做错了什么。我相信我已经找到了问题所在。默认情况下,Eclipse似乎以不同的方式构造jar,将目录条目省略
使用unzip-v调查档案可以发现一些有趣的细节
使用Ant创建的文件:
Archive: JSGFDemo.jar
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 2013-03-31 03:13 00000000 META-INF/
284 Defl:N 210 26% 2013-03-31 03:13 ddd976ff META-INF/MANIFEST.MF
0 Stored 0 0% 2013-03-31 03:08 00000000 edu/
0 Stored 0 0% 2013-03-31 03:08 00000000 edu/cmu/
0 Stored 0 0% 2013-03-31 03:13 00000000 edu/cmu/sphinx/
0 Stored 0 0% 2013-03-31 03:12 00000000 edu/cmu/sphinx/demo/
0 Stored 0 0% 2013-03-31 03:13 00000000 edu/cmu/sphinx/demo/jsapi/
0 Stored 0 0% 2013-03-31 03:13 00000000 edu/cmu/sphinx/demo/jsapi/jsgf/
7391 Defl:N 3501 53% 2013-03-31 03:13 938438dd edu/cmu/sphinx/demo/jsapi/jsgf/JSGFDemo.class
798 Defl:N 326 59% 2013-03-31 03:13 647722fc edu/cmu/sphinx/demo/jsapi/jsgf/books.gram
204 Defl:N 140 31% 2013-03-31 03:13 789bb514 edu/cmu/sphinx/demo/jsapi/jsgf/commands.gram
9295 Defl:N 1500 84% 2013-03-31 03:13 3b519044 edu/cmu/sphinx/demo/jsapi/jsgf/jsgf.config.xml
1589 Defl:N 473 70% 2013-03-31 03:13 60075af0 edu/cmu/sphinx/demo/jsapi/jsgf/movies.gram
299 Defl:N 195 35% 2013-03-31 03:13 42e94d32 edu/cmu/sphinx/demo/jsapi/jsgf/music.gram
666 Defl:N 288 57% 2013-03-31 03:13 ca4b72f9 edu/cmu/sphinx/demo/jsapi/jsgf/news.gram
-------- ------- --- -------
20526 6633 68% 15 files
使用eclipse导出的Jar:
Archive: JSGFDemo-eclipse.jar
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
180 Defl:N 134 26% 2013-03-31 23:35 1e681d3b META-INF/MANIFEST.MF
7338 Defl:N 3537 52% 2013-03-31 23:29 ed8c4c3f edu/cmu/sphinx/demo/jsapi/jsgf/JSGFDemo.class
798 Defl:N 326 59% 2013-03-31 13:21 647722fc edu/cmu/sphinx/demo/jsapi/jsgf/books.gram
204 Defl:N 140 31% 2013-03-31 13:21 789bb514 edu/cmu/sphinx/demo/jsapi/jsgf/commands.gram
9295 Defl:N 1500 84% 2013-03-31 13:21 3b519044 edu/cmu/sphinx/demo/jsapi/jsgf/jsgf.config.xml
1589 Defl:N 473 70% 2013-03-31 13:21 60075af0 edu/cmu/sphinx/demo/jsapi/jsgf/movies.gram
299 Defl:N 195 35% 2013-03-31 13:21 42e94d32 edu/cmu/sphinx/demo/jsapi/jsgf/music.gram
666 Defl:N 288 57% 2013-03-31 13:21 ca4b72f9 edu/cmu/sphinx/demo/jsapi/jsgf/news.gram
-------- ------- --- -------
20369 6593 68% 8 files
在快速搜索之后,我在Eclipse的jar导出向导中找到了“添加目录条目”选项 缺少资源的唯一原因是缺少资源。此错误意味着您的类路径中没有相应的路径。可能您对包的命名不同,并且没有更改config.xml文件中的路径。您需要提供有关项目布局、项目文件结构等的更多信息,以便获得更有意义的答案。@NikolayShmyrev据我所知,JAR具有相同的文件结构。如果您愿意,可以查看一下它们:如果我附加了某个特定文件的文件名,比如resource:/edu/cmu/sphinx/demo/jsapi/jsgf/commands.gram,那么我不会得到错误,但是显然,当sphinx尝试引用resource:/edu/cmu/sphinx/demo/jsapi/jsgf/command.gram时,这在以后不会起作用