Dear Jython Developers,
i would like to to use Jython with Java Web Start. I would like to embed
Jython Scripts in my application. I don=B4t want to use jythonc, because =
i
want to deliver the Jython scripts independently of the jars of my
application. Even our users should be allowed to write their custom
jython scripts. My application has to run with or without WebStart. If i
run my application without WebStart, it works. I use Jython 2.0. If i
run my application with WebStart, i get the following Error Message:
File "<iostream>", line 3, in ?
ImportError: no module named de
I use the following test program to invoke the Jython interpreter:
package de.disy.lfu.sds;
import java.util.Properties;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import javax.swing.table.DefaultTableModel;
import org.python.util.PythonInterpreter;
import org.python.core.PyObject;
import org.python.core.PyJavaInstance;
import org.python.core.PyException;
import de.disy.lfu.sds.server.Globals;
public class JythonTest {
public static void main( String[] args ) {
Globals.createGlobals(); // some initialization
try {
File tmpFile =3D File.createTempFile( "jython", null ); // to get
the name of the System temp directory
tmpFile.delete();
Properties props =3D new Properties();
props.setProperty( "python.cachedir", new File(
tmpFile.getParent(), "jythoncache" ).getAbsolutePath() ); // set the
jython cachedir to the directory "jythoncache" in the temp directory
PythonInterpreter.initialize( System.getProperties(), props, new
String[] { "" } );
// Globals.getCodeBase() gets the CodeBase, if the Application
runs with WebStart, or the current directory, if the Application runs
without WebStart
URL url =3D new URL( Globals.getCodeBase(),
"Repositories/Scripts/MesstellenFilter.py" );
InputStream is =3D url.openStream();
PythonInterpreter interp =3D new PythonInterpreter();
interp.execfile( is );
PyObject setResult =3D interp.get( "setResult" );
setResult.__call__( new PyJavaInstance( new DefaultTableModel() )
);
}
catch( IOException e ) {
e.printStackTrace();
}
catch( PyException e ) {
e.printStackTrace();
throw e;
}
}
}
The Jython-Script "Messtellenfilter.py" has the following content:
from jarray import array
from de.disy.lib.table import TableOperations
from de.disy.lib.table import Table
from de.disy.lib.table import Comparator
from de.disy.lib.table import DefaultComparator
from de.disy.lib.tools import DebugStream
def setResult( result ):
global bereich
table =3D Table( result ).mapColumns( array( [1], 'i' ) )
table =3D TableOperations.distinct( table, array( [0], 'i' ), array(
[DefaultComparator()], Comparator ) )
if table.rowCount =3D=3D 1:
bereich =3D table.get( 0, 0 ).intValue()
else:
bereich =3D None
DebugStream.println( "setResult" );
def acceptSelector( selector ):
if selector =3D=3D "MesswertS.sel":
return bereich =3D=3D 3
elif selector =3D=3D "MesswertS2.sel":
return bereich =3D=3D 7
Maybe the problem is that Jython uses its own ClassLoader, and WebStart
uses its own ClassLoader too. Maybe Jython expects the classes used in
the script to reside in the ClassPath. Because WebStart uses its own
ClassLoader, the classes aren't in the ClassPath, the ClassPath contains
only two JNLP specific Jars.
Best regards,
Romano Caserta
-- =
++ Besuchen Sie uns auf der begleitenden Fachausstellung zur =
++ Umweltinformatik 2001, dem 15.Internationalen Symposium Informatik
++ f=FCr den Umweltschutz vom 10.- 12.10.2001 in der ETH Z=FCrich, Schwei=
z.
++ Weitere Informationen:
++ http://www.empa.ch/deutsch/fachber/empasg/iep01/Exhibition.htm
+--------------------------------------------------------------------+
| Romano Caserta ca...@di... |
| disy Informationssysteme GmbH http://www.disy.net |
| Stephanienstr. 30 Tel: +49 721 1600-630 |
| D-76133 Karlsruhe, Germany Fax: +49 721 1600-605 |
+--------------------------------------------------------------------+
++disy - wir optimieren Ihre Informations- und Kommunikationsprozesse++
|