You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2007/01/08 15:54:54 UTC
svn commit: r494082 - in /incubator/uima/uimaj/trunk/uima-docbooks:
build_references.xml src/docbook/references/ref.pear.xml
Author: mbaessler
Date: Mon Jan 8 06:54:54 2007
New Revision: 494082
URL: http://svn.apache.org/viewvc?view=rev&rev=494082
Log:
JIRA ticket UIMA-161 (https://issues.apache.org/jira/browse/UIMA-161)
add some samples for the PEAR installer API.
Modified:
incubator/uima/uimaj/trunk/uima-docbooks/build_references.xml
incubator/uima/uimaj/trunk/uima-docbooks/src/docbook/references/ref.pear.xml
Modified: incubator/uima/uimaj/trunk/uima-docbooks/build_references.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uima-docbooks/build_references.xml?view=diff&rev=494082&r1=494081&r2=494082
==============================================================================
--- incubator/uima/uimaj/trunk/uima-docbooks/build_references.xml (original)
+++ incubator/uima/uimaj/trunk/uima-docbooks/build_references.xml Mon Jan 8 06:54:54 2007
@@ -19,7 +19,7 @@
under the License.
-->
-<project default="all" basedir=".">
+<project default="all" basedir="." name="Apache UIMA references documentation">
<!-- ======================================================================== -->
<!-- == == -->
Modified: incubator/uima/uimaj/trunk/uima-docbooks/src/docbook/references/ref.pear.xml
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uima-docbooks/src/docbook/references/ref.pear.xml?view=diff&rev=494082&r1=494081&r2=494082
==============================================================================
--- incubator/uima/uimaj/trunk/uima-docbooks/src/docbook/references/ref.pear.xml (original)
+++ incubator/uima/uimaj/trunk/uima-docbooks/src/docbook/references/ref.pear.xml Mon Jan 8 06:54:54 2007
@@ -556,12 +556,120 @@
<quote>.pear</quote> extension.</para>
</section>
- <section id="ugr.ref.pear.installing">
- <title>Installing a PEAR file</title>
+ </section>
+ <section id="ugr.ref.pear.installing">
+ <title>Installing a PEAR package</title>
+
+ <para>The installation of a PEAR package can be done in two different ways. It is either possible to install a PEAR package
+ using the PEAR installer tool or the PEAR API if the PEAR file should be installed out of an
+ application. The two possibilities are described here:
+
+ <itemizedlist>
+ <listitem><para> <xref linkend="ugr.ref.pear.installing_pear_using_pearInstaller"/></para></listitem>
+ <listitem><para> <xref linkend="ugr.ref.pear.installing_pear_using_API"/></para></listitem>
+ </itemizedlist>
+ </para>
+
+ <section id="ugr.ref.pear.installing_pear_using_pearInstaller">
+ <title>Installing a PEAR file using the PEAR Installer</title>
- <para>For information about the installation of a PEAR file and the PEAR Installer
- tool, please see <olink targetdoc="&uima_docs_tools;"
+ <para>For information about the installation of a PEAR package using the PEAR Installer
+ tool, please see <olink targetdoc="&uima_docs_tools;"
targetptr="ugr.tools.pear.installer"/>.</para>
</section>
+
+ <section id="ugr.ref.pear.installing_pear_using_API">
+ <title>Installing a PEAR file using the PEAR API</title>
+
+ <para>To install a PEAR package out of an application the PEAR API must be used. The PEAR API installes the PEAR package
+ in the same way as the PEAR installer tool did. The example below shows how to use the PEAR API to install a
+ PEAR package and access the installed PEAR package data. For more details about the PackageBrowser API,
+ please refer to the JavaDocs for the org.apache.uima.pear.tools package.
+ </para>
+
+ <programlisting>
+ File installDir = new File("/home/user/uimaApp/installedPears");
+ File pearFile = new File("/home/user/uimaApp/testpear.pear");
+ boolean doVerification = true;
+
+ try {
+
+ // install PEAR package
+ PackageBrowser instPear = PackageInstaller.installPackage(
+ installDir, pearFile, doVerification);
+
+ // retrieve installed PEAR data
+ // PEAR package classpath
+ String classpath = instPear.buildComponentClassPath();
+ // PEAR package main component descriptor
+ String mainComponentDescriptor = instPear
+ .getInstallationDescriptor().getMainComponentDesc();
+ // PEAR package component ID
+ String mainComponentID = instPear
+ .getInstallationDescriptor().getMainComponentId();
+
+ // print out settings
+ System.out.println("PEAR package class path: " + classpath);
+ System.out.println("PEAR package mainComponentDescriptor: "
+ + mainComponentDescriptor);
+ System.out.println("PEAR package mainComponentID: "
+ + mainComponentID);
+
+ } catch (PackageInstallerException ex) {
+ // catch PackageInstallerException - pear installation failed
+ ex.printStackTrace();
+ System.out.println("PEAR installation failed");
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ System.out.println("Error retrieving installed PEAR settings");
+ }
+ </programlisting>
+
+ <para>
+ To run a PEAR package after it was installed using the PEAR API see the sample below. It use the UIMA classloader
+ extension to set the classpath of the installed PEAR dynamically. For more details about the APIs please refer
+ to the JavaDocs.
+ </para>
+
+ <programlisting>
+ File installDir = new File("/home/user/uimaApp/installedPears");
+ File pearFile = new File("/home/user/uimaApp/testpear.pear");
+ boolean doVerification = true;
+
+ try {
+
+ // Install PEAR package
+ PackageBrowser instPear = PackageInstaller.installPackage(
+ installDir, pearFile, doVerification);
+
+ // Create resouce manager and set PEAR package classpath
+ ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager();
+ // Set PEAR package classpath and use it also to resolve resources
+ rsrcMgr.setExtensionClassPath(
+ instPear.buildComponentClassPath(), true);
+
+ // Create analysis engine from the installed PEAR package
+ XMLInputSource in = new XMLInputSource(instPear
+ .getInstallationDescriptor().getMainComponentDesc());
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser()
+ .parseResourceSpecifier(in);
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(
+ specifier, rsrcMgr, null);
+
+ // Create a CAS with a sample document text
+ CAS cas = ae.newCAS();
+ cas.setDocumentText("Sample text to process");
+ cas.setDocumentLanguage("en");
+
+ // Process the sample document
+ ae.process(cas);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ </programlisting>
+
+ </section>
+
</section>
+
</chapter>