This page describes how to invoke the java2python script, j2py.
The simplest way to use java2python is with the j2py command
and the name of an input file and output file:
$ j2py [INPUT] [OUTPUT]Both are optional, but you'll usually supply an input file:
$ j2py SourceFile.javaThe j2py command accepts options that alter its behavior.
The behavior of the code generator is not part of the command itself;
to change code generation behavior, refer to the customization
page.
-
[INPUT]Read from the given file. Specify
-forstdin. If not given the command will read fromstdin.If
[INPUT]is a directory, the script will walk the directory looking for files named.java, and transform each one. If[OUTPUT]is also a directory, the directory structure of[INPUT]will be recreated below it.If
[INPUT]is a directory,[OUTPUT]must also be a directory, or it may be-or unspecified. -
[OUTPUT]Write to the given file. Specify
-forstdout. If not given the command will write tostdout. -
-l LEVEL,--log-level LEVELSet the logging package to the specified log level. The log level may given as an integer (e.g.,
50for critical) or by name (e.g.,CRITICAL,Critical, orcritical). -
-c NAME,--config NAMEUse the specified configuration module or file. This option may be repeated.
Configuration modules/files are referenced in reverse order, i.e., from the final value given to the first given, with the default configuration referenced last.
See the customization page for details of the configuration system and available configuration points.
-
-d DIR,--config-dir DIRUse the given directory name to match input file names to configuration file names. This option may be repeated.
For example, to translate
FooBar.javaand use the configuration stored in./cfg/FooBar.py, specify-d ./cfg. -
-k,--skip-compileDo not byte compile the output to test for valid Python syntax.
-
-n,--no-defaultsIgnore the default configuration module.
-
-r,--no-colorDisable colorized output.
Colorized output is not available on Windows and this option is ignored there.
-
-p,--python-treePrint a representation of the internal Python code tree. Representation is written to
stderr. -
-j,--java-astPrint a representation of the Java abstract syntax tree. Representation is written to
stderr. -
-f,--profileProfile execution and print the results to
stderr. -
-s,--skip-sourceDo not write generated source. This most useful in development of java2python itself and when combined with
-pand/or-j.
-
-h,--helpShow a help message and exit
-
-v,--versionShow the program version number and exit.