- Fixing classpath scanning in Jython
- Out of memory
- expr: syntax error - if jython is a symlink
- Verbose dependency resolving
- Flush caches
- Using SNAPSHOT versions
- Updating Jython to use JDK 7
- UnicodeEncodeError: ‘charmap’ codec can’t encode character ….
- Known problems
- Comparison to Groovy scripts
Fixing classpath scanning in Jython
Each Jython script require these commands at the beginning of the script to allow uimaFIT access to the dynamically imported dependencies (see below).
Note: A feature request to set the context classloader automatically when entering a Jython context has been filed upstream (Jython issue 2142).
Out of memory
If a script complains about not having enough heap, try the command
and then run the script again.
expr: syntax error - if jython is a symlink
If you set up a symlink to the
jythoncommand, you may be seeing the error
expr: syntax error whenever you run a script. This has been discussed [http://sourceforge.net/p/jython/mailman/message/31323567/ here]. The solution is to open the file
jythonin a text editor, locate the line
and replace it with the line
Verbose dependency resolving
Normally, grape resolves dependencies quietly. If a script has many dependencies, that can mean the script may be running for a long time without any visible output on screen, looking like it is hanging. What it really does is downloading the dependencies. To enable verbose output during the dependency resolving phase, set JAVA_OPTS:
The scripts download required models and libraries automatically. Sometimes it may be necessary to flush the cache folders. There are two cache folders that you can clear to force re-downloading the dependencies:
~/.jip/cache- dependencies referenced from the Jython scripts are store here
~/.ivy2/cache- models and resources dynamically downloaded by DKPro Core components
Using SNAPSHOT versions
To use SNAPSHOT versions of DKPro Core, add the following lines before the
require(...) lines used to fetch the dependencies.
Then change the versions of all DKPro Core components to the SNAPSHOT version that you wish to use. It is strongly recommended not to mix versions!
Updating Jython to use JDK 7
Running the TreeTagger example might throw an exception like:
This is due fact that Jython is using JDK 6 instead of JDK 7. Ensure that JDK 7 is installed. For Linux systems, you might need to update the file
/usr/bin/jython. In the 6th line you find
JAVA_HOME="/usr/lib/jvm/java-6-openjdk-amd64/jre". Replace the
java-7 and it should work. To check the Java version that is used by Jython, execute
UnicodeEncodeError: ‘charmap’ codec can’t encode character ….
You may get an exception like UnicodeEncodeError: ‘charmap’ codec can’t encode character …. when writing Unicode texts to the console on systems such as Windows where UTF-8 is not the default system encoding. To fix this, you can override the Jython console encoding:
Custom UIMA components
It is currently not possible to define new UIMA component classes (readers or analysis engines) in Python. The respective classes cannot be found and instantiated by the UIMA framework. The following script will therefore produce an exception:
The produced exception is this:
Related issue: [https://issues.apache.org/jira/browse/UIMA-3692 UIMA-3692]
Comparison to Groovy scripts
The Python (Jython) scripts are very similar to the Groovy scripts. The main differences (except for the different syntax) are:
Custom UIMA components
It is currently not possible to define custom UIMA components in Jython scripts. In Groovy scripts, this is possible.