Skip to content

Import Java packages into Python - Syntax sugar for PyJNIus or JavaBridge

License

Notifications You must be signed in to change notification settings

Arnie97/import-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

import-java

Build Status Code Coverage PyPI Version Python Compatibility License

Import your Java packages seamlessly into CPython.

Quick Start

We'll create a temporary file in Java and then read it in Python to illustrate the usage:

>>> import java
>>> with java:
...     from java.lang import String
...     from java.nio.file import Files
...
>>> temp_path = Files.createTempFile('sample', '.tmp')
>>> sample_text = String('Greetings from Java')
>>> Files.write(temp_path, sample_text.getBytes())
<java.nio.file.Path at 0x... jclass=java/nio/file/Path jself=...>

>>> with open(temp_path.toString()) as f:
...     print(repr(f.read()))
...
'Greetings from Java'

You can also use _ as a short alias for java.lang:

>>> with java:
...     from _ import System
...
>>> System.getProperty('java.specification.version')
'1.8'

Wildcard imports (such as from java.util import *) are not supported yet.

Dependencies

Either PyJNIus or JavaBridge. PyJNIus is preferred, as JavaBridge cannot disambiguate overloaded methods with the same number of parameters.

Installation

$ pip install import-java

License

MIT.

See also

About

Import Java packages into Python - Syntax sugar for PyJNIus or JavaBridge

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages