davidrmcharles
davidrmcharles

Reputation: 1953

Jython 2.7b4 will not webstart: ImportError: No module named site

I injected my application into jython-standalone-2.7-b4.jar. Here is what I see in the webstart console of the client machine when I webstart my app:

Java Web Start 11.31.2.13
Using JRE version 1.8.0_31-b13 Java HotSpot(TM) 64-Bit Server VM
User home directory = C:\Users\me
...
#### Java Web Start Error:
#### null

When I click on 'Details', I find the following exception stack trace:

ImportError: No module named site

    at org.python.core.ImportError(Py.java:328)
    at org.python.core.imp.import_first(imp.java:842)
    at org.python.core.imp.load(imp.java:695)
    at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:118)
    at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:94)
    at org.python.util.InteractiveInterpreter.<init>(InteractiveInterpreter.java:39)
    at org.python.util.InteractiveInterpreter.<init>(InteractiveInterpreter.java:28)
    at org.python.util.InteractiveConsole.<init>(InteractiveConsole.java:67)
    at org.python.util.InteractiveConsole.<init>(InteractiveConsole.java:53)
    at org.python.util.InteractiveConsole.<init>(InteractiveConsole.java:33)
    ...

Jython2.7b1 worked for me. I tried Jython2.7b3, but that fails as well.

Upvotes: 1

Views: 490

Answers (1)

Alex Gr&#246;nholm
Alex Gr&#246;nholm

Reputation: 5911

Due to class loader differences in the Web Start environment, Jython can't find the files in the Lib directory inside the standalone jar file. To fix this, you need to rearrange the contents of the standalone jar a bit. The following script will convert a standalone jar into something workable in a Web Start environment:

#!/bin/sh
# Converts a Jython standalone jar into something usable with Java Web Start
if [ -z $1 ]; then
  echo "Please give the path to the standalone jar as the first argument."
  exit 1
fi

CURRDIR=$(pwd)
JAR_PATH="$CURRDIR/$1"
CONVERTED_JAR_PATH="$CURRDIR/jython-webstart.jar"
TEMPDIR=$(mktemp -d)
cd "$TEMPDIR"
jar xf "$JAR_PATH"
rm -rf Lib/test  # including Jython's own unit tests is pointless
java -jar "$JAR_PATH" -m compileall Lib
find Lib -name "*.py" -delete
mv Lib/* .
rmdir Lib
jar cf "$CONVERTED_JAR_PATH" *
rm -rf "$TEMPDIR"

Next you'll probably run into Jython bug 2283. To work around it, set the python.home system property to point to any existing directory.

Upvotes: 1

Related Questions