Question

When building the JSGFDemo using ant, everything works fine. Running the JSGFDemo.jar build artifact works without any errors. However, when using source folder imported in eclipse, and adding the jars in the lib/ directory to the build path, the program errors with the following message:

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/

For some reason the call to ConfigurationManagerUtils.class.getResource(resourceName); in ConfigurationManagerUtils.resourceToURL(String location) seemingly returns different results for location = "resource:/edu/cmu/sphinx/demo/jsapi/jsgf/". (null, or a valid URL-object)

As a sidenote, I thought getResource("/path/to/a/dir/not/file/"); was invalid when it would resolve to a path inside a jar.

I've been banging my head against this for a while now and can't see what I'm doing wrong.

Was it helpful?

Solution

I believe to have found the issue. By default, Eclipse seems to construct the jar differently, leaving out entries for directories.

Investigating the archives with unzip -v reveals some interesting details.

File from building with 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

Jar exported using eclipse:

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

After a quick google, I found the "Add directory entries" option in Eclipse's jar export wizard.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top