Sunday, 2 December 2007

jython call 3rd party java class file

Accessible Class
Every functions (including constructor) and the class declaration must start with public.

Jython call class Notes
For instance, if you want to initialize an object form your class, you should run
>>>gc = GetConf();
the '()' is needed! Just remember, python loves (), the basic function dir() must followed ().

About Path
1. in terminal, go to the folder where the class file is. then run jython,and import the name of the calss. Now you can get a instance of that.

2. at runtime, you could do:

>>> import sys
>>> sys.path.append('/path/to/module')

A few rules about CLASSPATH and python.path:

  • sys.path in the registry file -- Add here to enable importing from Java classes (.java), Java class libraries (.jar), and Jython/Python (.py).
  • CLASSPATH -- Add here to enable importing from Java classes (.java) and Java class libraries (.jar), but not Jython/Python (.py).

No comments:

My photo
London, United Kingdom

Facebook & Twitter