sphinx grammarLocation无法定位资源

时间:2013-03-31 12:59:59

标签: 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/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(String location)的调用似乎会返回location =“resource:/ edu / cmu / sphinx / demo / jsapi / jsgf /”的不同结果。 (null或有效的URL对象)

作为旁注,我认为是getResource(“/ path / to / a / dir / not / file /”);当它解析为jar中的路径时无效。

我现在一直在反对这个问题,看不出我做错了什么。

1 个答案:

答案 0 :(得分:1)

我相信找到了这个问题。默认情况下,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导出向导中找到了“添加目录条目”选项。