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
|