From: Kevin S. <se...@mo...> - 2002-10-26 15:36:57
|
this could be a classloader issue. well, not so much of a classloader = issue as an issue with how jython finds java classes. essentially, it = just looks at the value of the system property java.class.path to find = jars/classes it thinks it should know about. however, if you are using = something like a servlet container that uses a specialized classloader = (i.e. one that adds all jars in some lib directory to the classpath), = jython probably won't find classes that you think it should. one way to work around this is to use PySystemState.add_extdir() to add = extra directories to the list where jython will look for (and process) = jars. here's a little snippet of code we use to do this: // initialize jython runtime Properties jythonProps =3D new Properties(); String motiveHome =3D Config.getProperty("motive.home"); File pythonHome =3D new File(motiveHome, "jython"); jythonProps.setProperty("python.home", pythonHome.getAbsolutePath()); PySystemState.initialize(System.getProperties(), jythonProps, new String[]{""}); // add extra directories in which jython should look for jars. // jython.extradirs property can be a comma-separated list of // extra dirs. any directories listed that are not absolute // paths will have motive.home prepended to them. String jythonExtraDirs =3D Config.getProperty("jython.extradirs", "tomcat/lib"); StringTokenizer st =3D new StringTokenizer(jythonExtraDirs, ","); while (st.hasMoreTokens()) { String s =3D st.nextToken(); File dir =3D new File(s); if (!dir.isAbsolute()) { dir =3D new File(motiveHome, s); } PySystemState.add_extdir(dir.getAbsolutePath(), true); } -----Original Message----- From: Wilcox, Jim [mailto:JW...@cr...] Sent: Friday, October 25, 2002 3:33 PM To: 'jyt...@li...' Subject: [Jython-dev] help! Dear Jython Developers, I have a java application and an attempting to integrate a Jython = utility another developer wrote into it and call it within my java code. = Using your documentation it appeared I needed to embed the Jython = utility using PythonInterpreter but it pukes on any import java module. What am I doing wrong, or is what I am attempting to do not supported? Thanks in advance for any help! Jim=20 Here is my puking attempt: package test.creekpath.verification.AIMaze.utilities; import org.python.util.PythonInterpreter; import org.python.core.*; import java.util.Properties; public class JythonOperations { public void runcatsutility() //String[] inputparameters { Properties jythonsysprops =3D new Properties(); Properties jythonregprops =3D new Properties(); jythonregprops.setProperty("python.home", = "/jython-2.1"); jythonregprops.setProperty("python.path", = "/jython-2.1"); //put back in if need /* jythonregprops.setProperty("python.cachedir ", = "/jython-2.1/cachedir"); */ PythonInterpreter.initialize(jythonsysprops, jythonregprops, new String[0]); = //String[] argv PythonInterpreter interp =3D new PythonInterpreter(); System.out.println("Loading Cats Utility"); interp.execfile("C:\\jython-2.1\\__run__.py"); } //end method runcatsutility } //end class JythonOperations Here is the bat file that works running from the Jython directory: @echo off rem set JAVA_HOME=3DC:\Program Files\JavaSoft\JRE\1.3.1 set ARGS=3D :loop if [%1] =3D=3D [] goto end set ARGS=3D%ARGS% %1 shift goto loop :end set SYMPY_HOME=3DC:\jython-2.1 set JAVA_HOME=3Dc:\AIM\ThirdParty\jdk1.3-win32 "%JAVA_HOME%\bin\java.exe" "-Dpython.home=3D%SYMPY_HOME%" -classpath = "%SYMPY_HOME%\jython.jar;%SYMPY_HOME%\jylib.jar;C:\AIM\ThirdParty\Oracle\= JDBC\lib\classes12.zip" org.python.util.jython __run__.py %ARGS% |