Package: rubicon-java
Rubicon-JavaRubicon-Java is a bridge between the Java Runtime Environment and Python.
It enables you to:Instantiate objects defined in Java,Invoke static and instance methods on objects defined in Java,Access and modify static and instance fields on objects defined in Java, andWrite and use Python implementations of interfaces defined in Java.QuickstartRubicon-Java consists of three components:A Python library,A JNI library, andA Java JAR file.AMakefilehas been provided to compile the JNI and JAR components. Type:$ maketo compile them. The compiled output will be placed in thebuilddirectory.To use Rubicon-Java, you’ll need to ensure:rubicon.jaris in the classpath when you start your Java VM.The Rubicon library file is somewhere that it will be found by dynamic
library discovery. This means:Under OS X, put the directory containinglibrubicon.dylibis in yourDYLD_LIBRARY_PATHUnder Linux, put the directory containinglibrubicon.sois in yourLD_LIBRARY_PATHUnder Windows…. something :-)TherubiconPython module is somewhere that can be added to aPYTHONPATH. You can install rubicon using:$ pip install rubicon-javaIf you do this, you’ll need to reference your system Python install when
setting yourPYTHONPATH.The Rubicon bridge starts on the Java side. Import the Python object:import org.beeware.rubicon.Python;Then start the Python interpreter, and run a Python file:# Initialize the Python VM
String pythonHome = "/path/to/python";
String pythonPath = "/path/to/dir1:/path/to/dir2";
if (Python.start(pythonHome, pythonPath, null) != 0) {
    System.out.println("Error initializing Python VM.");
}

# Start a Python module
if (Python.run("path.of.module") != 0) {
    System.out.println("Error running Python script.");
}

# Shut down the Python VM.
Python.stop();ThePYTHONPATHyou specify must enable access to therubiconPython
module.In your Python script, you can then reference Java objects:>>> from rubicon.java import JavaClass

# Wrap a Java class
>>> URL = JavaClass("java/net/URL")

# Then instantiate the Java class, using the API
# that is exposed in Java.
>>> url = URL("https://beeware.org")

# You can then call methods on the Java object as if it
# were a Python object.
>>> print(url.getHost())
beeware.orgIt’s also possible to provide implementations of Java Interfaces in Python.
For example, lets say you want to create a Swing Button, and you want to
respond to button clicks:>>> from rubicon.java import JavaClass, JavaInterface

# Wrap the Java interface
>>> ActionListener = JavaInterface('java/awt/event/ActionListener')

# Define your own implementation
>>> class MyActionListener(ActionListener):
...     def actionPerformed(self, event):
...         print("Button Pressed")

# Instantiate an instance of the listener
>>> listener = MyActionListener()

# Create a button, and set the listener
>>> Button = JavaClass('javax/swing/JButton')
>>> button = Button('Push it')
>>> button.setActionListener(listener)Of course, this sample code won’t work unless it’s in the context of a larger
application starting a Swing GUI and so on.TestingTo run the Rubicon test suite:Ensure thatjavais on your$PATH, or set theJAVA_HOMEenvironment
variable to point to a directory of a Java Development Kit (JDK).Create a Python 3 virtual environment, and ensure that pip & setuptools are
up to date:$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ python -m pip install --upgrade pip
(venv) $ python -m pip install --upgrade setuptoolsInstalltox:(venv) $ python -m pip install toxRun the test suite. The following should work properly on both macOS and
Linux:(venv) $ tox -e pyThis will compile the Rubicon library, compile the Java test classes, and
run the Python test suite from within the Java environment.DocumentationFull documentation for Rubicon can be found onRead The Docs.CommunityRubicon is part of theBeeWare suite. You can talk to the community through:@PyBeeWare on TwitterThebeeware/generalchannel on Gitter.We foster a welcoming and respectful community as described in ourBeeWare Community Code of Conduct.ContributingIf you experience problems with this backend,log them on GitHub. If you
want to contribute code, pleasefork the codeandsubmit a pull request.