You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Egbert van der Wal <ew...@pointpro.nl> on 2012/11/23 10:28:56 UTC
Loading annotators from resources in JAR-file
Hello,
I've been looking all over the internet for this, but I can't find a
proper working solution. I'm currently developing a system that needs to
run independently on any machine with a JVM. Therefore, I would like to
package everything inside a single JAR-file. Preferably including UIMA,
but I'm not sure if the license allows this?
Anyway, I have created several annotators and one aggregate annotator
that links to these annotators using a relative path. The aggregate
annotator is in desc/analysis engines/ and the annotators are in
desc/annotators. The aggregate annotator links to the annotatiors like
so: ../annotators/MyAnnotator.xml
Because the files are being packaged in a JAR-file, I am using
getClass().getClassLoader().getResourceAsStream("analysis
engines/MyAE.xml") to load the engine and pass that to the
XMLInputReader. This all seems to work, however, the function
parseResourceSpecifier tries to load the linked annotators and complains
it cannot find them. So fix the path issues, I replaced
'getResourceAsStream' with 'getResource' which results in a URL. The
XMLInputReader also accepts a URL, so that also works, but it gives the
same problem.
I think the problem more or less lies in the relative path, which messes
up the resource in the URL.However, I tried changing the paths to
annotators/MyAnnotator.xml or /annotators/MyAnnotator.xml, but this also
doesn't work, and in addition, makes the Component Descriptor Editor in
Eclipse fail to read the file as it also cannot find the file.
So, the big question is: what is the proper procedure to read and
reference annotators packaged within a JAR-file?
For reference, this is the error I'm getting when running the JAR-file
(it all works fine from the development environment):
org.apache.uima.resource.ResourceInitializationException: Import
failed. Could not read from URL rsrc:../annotators/MyAnnotator.xml.
(Descriptor: rsrc:analysis%20engines/MyAE.xml)
at
org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initialize(AggregateAnalysisEngine_impl.java:159)
at
org.apache.uima.impl.AnalysisEngineFactory_impl.produceResource(AnalysisEngineFactory_impl.java:94)
at
org.apache.uima.impl.CompositeResourceFactory_impl.produceResource(CompositeResourceFactory_impl.java:62)
at
org.apache.uima.UIMAFramework.produceResource(UIMAFramework.java:269)
at
org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:354)
at
nl.novay.keywordSpotter.KeywordSpotter.initializeEngine(KeywordSpotter.java:222)
at nl.novay.keywordSpotter.KeywordSpotter.main(KeywordSpotter.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.apache.uima.util.InvalidXMLException: Import failed.
Could not read from URL rsrc:../annotators/MyAnnotator.xml. (Descriptor:
rsrc:analysis%20engines/MyAE.xml)
at
org.apache.uima.analysis_engine.impl.AnalysisEngineDescription_impl.resolveDelegateAnalysisEngineImports(AnalysisEngineDescription_impl.java:812)
at
org.apache.uima.analysis_engine.impl.AnalysisEngineDescription_impl.resolveDelegateAnalysisEngineImports(AnalysisEngineDescription_impl.java:765)
at
org.apache.uima.analysis_engine.impl.AnalysisEngineDescription_impl.getDelegateAnalysisEngineSpecifiers(AnalysisEngineDescription_impl.java:193)
at
org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initialize(AggregateAnalysisEngine_impl.java:147)
... 11 more
Caused by: java.net.MalformedURLException: Could not open InputStream
for URL 'rsrc:../annotators/MyAnnotator.xml'
at
org.eclipse.jdt.internal.jarinjarloader.RsrcURLConnection.getInputStream(RsrcURLConnection.java:46)
at org.apache.uima.util.XMLInputSource.<init>(XMLInputSource.java:120)
at
org.apache.uima.analysis_engine.impl.AnalysisEngineDescription_impl.resolveDelegateAnalysisEngineImports(AnalysisEngineDescription_impl.java:810)
... 14 more
Thanks for any suggestions!
Bye,
Egbert
Re: Loading annotators from resources in JAR-file
Posted by Egbert van der Wal <ew...@pointpro.nl>.
Op 23-11-12 11:37, Richard Eckart de Castilho schreef:
> Am 23.11.2012 um 10:28 schrieb Egbert van der Wal <ew...@pointpro.nl>:
>
>> Anyway, I have created several annotators and one aggregate annotator that links to these annotators using a relative path. The aggregate annotator is in desc/analysis engines/ and the annotators are in desc/annotators. The aggregate annotator links to the annotatiors like so: ../annotators/MyAnnotator.xml
>
> Sounds like you are using location-based imports in your descriptors. You should use name-baed imports - these are resolved against the classpath like Java classes, not against the file system as with location-based imports.
>
> -- Richard
>
Ah, thanks you very much, that was indeed the problem. I did not realize
there were two ways to import. Thanks a lot!
Bye,
Egbert
Re: Loading annotators from resources in JAR-file
Posted by Richard Eckart de Castilho <ec...@ukp.informatik.tu-darmstadt.de>.
Am 23.11.2012 um 10:28 schrieb Egbert van der Wal <ew...@pointpro.nl>:
> Anyway, I have created several annotators and one aggregate annotator that links to these annotators using a relative path. The aggregate annotator is in desc/analysis engines/ and the annotators are in desc/annotators. The aggregate annotator links to the annotatiors like so: ../annotators/MyAnnotator.xml
Sounds like you are using location-based imports in your descriptors. You should use name-baed imports - these are resolved against the classpath like Java classes, not against the file system as with location-based imports.
-- Richard
--
-------------------------------------------------------------------
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab (UKP-TUD)
FB 20 Computer Science Department
Technische Universität Darmstadt
Hochschulstr. 10, D-64289 Darmstadt, Germany
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckart@ukp.informatik.tu-darmstadt.de
www.ukp.tu-darmstadt.de
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------