Home www.python.org
Download Documentation
Documentation
Overview
Executive Summary
Invoking JPython
JPython Registry
Embedding
Compiling JPython from source
 
Working with Java
The Basics
JavaBean Properties
Java arrays
Subclassing
Building applets, servlets, beans...
 
Python Docs (exits)
Python Tutorial
Library Reference
 
Other
JPython vs. CPython
JPython FAQ
List Archives (exit)
JPython paper (exit)
 
Email Us
jpython@python.org
 
  

Invoking the JPython Interpreter

JPython can be invoked from the shell using the following command:

jpython [options] [-jar jar | -c cmd | file | -] [args]
Options and arguments:

-i inspect interactively after running script, and force prompts, even if stdin does not appear to be a terminal
-S don't imply import site on initialization
-X disable class based standard exceptions
-Dprop=value Set the Java property prop to value
-jar jar program to run is read from the __run__.py file in the specified jar file
-c cmd program to run is passed in as the cmd string. This option terminates the options list
file run file as the program script
- program is read from standard-in (default; interactive mode is used if on a tty). This flag allows you to pipe a file into JPython and have it be treated correctly. This would be useful in a case like: filter file | jpython -
--help print a usage message and exit
--version print JPython version number and exit
args arguments passed to the program in sys.argv[1:]

Details

jpython is a short script that invokes your local JVM, sets the Java property install.path to an appropriate value, and then runs the Java classfile org.python.util.jpython.

Making JPython Scripts Executable

To make a jpython ".py" file executable on a Unix system you can add the following line to the top of the file:

#! /usr/bin/env jpython

For this magic to work, you must have jpython somewhere on your standard PATH. You also must also make the ".py" file executable. Typically this is done with the command: chmod +x foo.py.

Note: "#! <...>/jpython" will probably not work to make your script executable. This is because "jpython" is itself a script, and the #! magic requires that the file to execute is a binary executable on most Unix variants. Using "/usr/bin/env" will get around this problem - and make your scripts more portable in the bargain.