In this post I’ll show you how to setup your own Jython environment.
Prerequisite to this, you must have a Java Runtime Environment (JRE) installed in your system. Chances are when you already have browser running some Java applet or Java Web Start application, you already have JRE installed on your system.
Get the latest JRE from http://java.com/en/download/manual.jsp.
First you need to download a Jython binaries installer, currently the latest one is version 2.5.1, which you could download from this link.
After download completion you should have a file named jython_installer-2.5.1.jar, click on the file, or run from command line:
$ java -jar jython_installer-2.5.1.jar
Or in some other platform:
c:\> java -jar jython_installer-2.5.1.jar
Now you need to add you Jython path to your OS Path variable, so that the shell or command line interpreter is able to find Jython. In my sample Windows installation case:
C:\> set PATH=%PATH%;c:\opt\env\jython2.5.1
Alternatively, if you are running bash shell (assuming you installed Jython to /opt/env/jython2.5.1 folder):
$ export PATH=$PATH:/opt/env/jython2.5.1
Now you may proceed with the first invocation of Jython.
C:\> jython *sys-package-mgr*: processing new jar, 'C:\opt\env\jython2.5.1\jython.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\resources.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\rt.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jsse.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\jce.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\charsets.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\dnsns.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\localedata.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\QTJava.zip' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunjce_provider.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunmscapi.jar' *sys-package-mgr*: processing new jar, 'C:\Program Files\Java\jre6\lib\ext\sunpkcs11.jar' Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54) [Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_16 Type "help", "copyright", "credits" or "license" for more information. >>>
The jython command line actually invoked a Windows batch file jython.bat, which
When first time invoked, Jython interpreter will activate sys-package-mgr to add standard Java library classes as Python package.
After the installation, just play around with simple thing such as:
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_16
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.lang import System
>>> System.out.println("Hello, world!")
Hello, world!
>>> System.out.println('Hello, world!')
Hello, world!
>>> System.currentTimeMillis()
1257145977410L
>>> from java.lang import String
>>> s = String("abc")
>>> s.toString()
u'abc'
Look at how System.out.println is able to receive both single quote and double quote Python string, and also the java.lang.String type by a Java class method is a Unicode string (u’abc’).
Posted by dbaktiar 








Posted by dbaktiar
Posted by dbaktiar 
.


Type in the data.



