I wanted to import a java package "TestPackage" into jython script,
import TestPackage
print TestPackage.SampleClass().getMessage();
I am getting the following error,
ImportError: No module named TestPackage","errorPoint":"","lineNumber":"1","errorPointMessage":"in <module>\nImportError: No module named TestPackage
When I use from TestPackage import SampleClass works fine. If I execute from <pacakage> import <anyclass> statement once, then import <pacakage> works without the import error.
I tried setting PySystemState.add_package("TestPackage"), this works but leading to memory leakage.
Is there any alternative way to make use of import TestPackage ? How can I use "import <packagename>" in jython without memory leakage?
org.example.test.TestPackagewould be imported asimport org.example.test.TestPackageorfrom org.example.test import TestPackage. Same as in Java :) If the jar file isn't on your Jython classpath, add it. As a quick hack,import sys; sys.path.append('/path/to/testpackage.jar')works. - IceArdor