From: David H. <dav...@gm...> - 2007-07-20 00:07:26
|
Hi, I am trying to embed my Jython code in a Java program, Eclipse to be exact, and I'm having trouble with class loading. My Python code fails to load classes that I know are accessible in the Java context where the PythonInterpreter was created. How can I make a PythonInterpreter able to use the same classes that are accessible in the code that creates it? I tried creating a PySystemState and setting its classloader, but it didn't work: try { Class.forName("org.eclipse.jface.viewers.IStructuredContentProvider"); System.out.println("Successfully loaded IStructuredContentProvider by name from Java"); } catch (Exception e) { System.out.println("Failed to load IStructuredContentProvider by name from Java"); } PySystemState.initialize(); PySystemState state = new PySystemState(); state.setClassLoader(Thread.currentThread().getContextClassLoader()); PythonInterpreter interpreter = new PythonInterpreter(null, state); try { interpreter.exec("from org.eclipse.jface.viewers import IStructuredContentProvider"); } catch (Throwable t) { System.out.println("Failed to import IStructuredContentProvider: " + t.toString()); } The class was loaded successfully in Java, but not in Python: Successfully loaded IStructuredContentProvider by name from Java Failed to import IStructuredContentProvider: Traceback (innermost last): File "<string>", line 1, in ? ImportError: no module named jface How should this be done? -David |