Compiling your Python code with jythonc

May, 2003

After you make your .py file you may want to compile it into a JAR file for distribution. The Jython distribution from contains a compiler called jythonc that can be used. Here are some steps you can take to create a JAR file of your code:

  1. Prerequsites:

  2. Make a batch file (or script) in the VisAD-Jython install directory to invoke the jythonc compiler. You can use the batch files in the VisAD-Jython installation directory as guidance. My script (which I called comp.bat) looks like this:
    @echo off
    set JYTHON_PATH=.
    set CLASSPATH=.
    %JYTHON_PATH%\jre\bin\java.exe -mx256m "-Dpython.home=%JYTHON_PATH%\\" "-Dpython .path=%JYTHON_PATH%.\\" -cp "%JYTHON_PATH%\\jython.jar;%JYTHON_PATH%\\visad.jar; %JYTHON_PATH%\\;." org.python.util.jython "%JYTHON_PATH%\Tools\jythonc\jythonc.p y " --compiler javac  %1 %2 %3 %4 %5 %6 %7 %8 %9
    (Note the "--compiler javac" option -- this assumes that the Java compiler to use (javac) is in your PATH.)

  3. Then to compile your .py script, you might do this:
    comp --core --jar mything.jar
    The documentation on jythonc can be found here and has all the details of the options.

  4. When you want to run your newly-created program, you might use something like this (in Windows):
    java -cp mything.jar;visad.jar mything

Back to Main Page