Browse files

Merge branch 'master' into method_patch

  • Loading branch information...
marscher committed Nov 4, 2018
2 parents 76696ee + 7802a53 commit 09ec730613d99a6d34709c4b683e6945a89dbcba
Showing with 286 additions and 73 deletions.
  1. +1 −0
  2. +1 −1 appveyor.yml
  3. +4 −0 doc/CHANGELOG.rst
  4. +10 −3 doc/
  5. +28 −6 doc/install.rst
  6. +6 −6 doc/userguide.rst
  7. +41 −6 jpype/
  8. +7 −3 jpype/
  9. +65 −41 jpype/
  10. +0 −1 native/python/jpype_python.cpp
  11. +6 −1 setupext/
  12. +67 −0 test/jpypetest/
  13. +50 −5 test/jpypetest/
@@ -3,5 +3,6 @@ recursive-include examples *
include *.rst doc/* LICENSE
# include everything under test/
graft test
graft setupext
global-exclude *.pyc
prune test/classes
@@ -4,7 +4,7 @@ environment:
# /E:ON and /V:ON options are not enabled in the batch script intepreter
# See:
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
ANT_HOME: "C:\\ProgramData\\chocolatey\\lib\\ant\\apache-ant-1.10.1"
ANT_HOME: "C:\\ProgramData\\chocolatey\\lib\\ant\\apache-ant-1.10.5"
NUMPY_: "numpy x.x"
JAVA_HOME: "C:\\jdk8"
@@ -4,6 +4,10 @@ Changelog
This changelog *only* contains changes from the *first* pypi release ( onwards.
- **Next version - unreleased**
- Changed startJVM() to report errors on unrecognized options by default.
Use `ignoreUnrecognized=True` to get previous behavior.
- Java reference counting has been converted to use JNI
- Added extra verbiage to the to the raised exception when an overloaded
method could not be matched. It now prints a list of all possible method
@@ -18,7 +18,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))
# -- General configuration ------------------------------------------------
@@ -44,14 +44,21 @@
# General information about the project.
project = u'JPype'
copyright = u'2014, Steve Menard, Luis Nell and others'
copyright = u'2014-18, Steve Menard, Luis Nell and others'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
# The short X.Y version.
import mock
mock_modules = ('_jpype',
for m in mock_modules:
sys.modules[m] = mock.MagicMock()
import jpype
version = jpype.__version__
# The full version, including alpha/beta/rc tags.
release = jpype.__version__
@@ -138,7 +145,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
#html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
@@ -1,7 +1,7 @@
Get JPype from the `github <>`__ or
Get JPype from the `github <>`__ or
from `PyPi <>`__. If you are using `Anaconda <>`_ Python stack,
you can install pre-compiled binaries from conda-forge for Linux, OSX and Windows.
@@ -20,12 +20,12 @@ Either the Sun/Oracle JDK/JRE Variant or OpenJDK. Python 2.6+ (including Python
Debian/Ubuntu users will have to install ``g++`` and ``python-dev``
Debian/Ubuntu users will have to install ``g++``, ``python-dev``, and ``ant``
sudo apt-get install g++ python-dev python3-dev
sudo apt-get install g++ python-dev python3-dev ant
@@ -35,8 +35,23 @@ Windows users need a Python installation and C++ compilers:
1. Install some version of Python (2.7 or higher), e.g., `Anaconda
<>`_ is a good choice for users not yet
familiar with the language
2. Install a `Windows C++ Compiler
2. For Python 2 series, Install `Windows C++ Compiler
3. For Python 3 series, Install `Microsoft Visual Studio 2010 Redistributable Package (x64)
<>`_ and
`Microsoft Build Tools 2015 Update 3
4. Install `Apache Ant (tested using 1.9.13)
Netbeans ant can be used in place of Apache Ant. Netbeans ant is located in
The Build Tools 2015 is a pain to find. Microsoft really wants people to download the latest version.
To get to it from the above URL, click on "Redistributables and Build Tools", then select
Microsoft Build Tools 2015 Update 3.
When building for windows you must use the Visual Studio developer command prompt.
@@ -48,6 +63,14 @@ Should be easy as
python install
For builds with a specific ant, use
python --ant=C:\My\Ant\Path\ant.bat install
If it fails...
@@ -60,7 +83,7 @@ This happens mostly due to the setup not being able to find your
``JAVA\_HOME=/usr/lib/java/jdk1.6.0/ python install``
2. Please create an Issue `on
github <>`__ and
github <>`__ and
post all the information you have.
Tested on
@@ -73,7 +96,6 @@ Tested on
- Debian 7.1 with OpenJDK 1.6.0
- Ubuntu 12.04 with Sun/Oracle JDK 1.6.0
Known Bugs/Limitations
@@ -408,26 +408,26 @@ regular Python classes. This contributes to the fact that it is not possible
to catch Java exceptions in a completely straightforward way.
All Java exceptions thrown end up throwing the jpype.JavaException exception.
You can then use the message(), stackTrace() and javaClass() to access
You can then use the message(), stacktrace() and javaClass() to access
extended information.
Here is an example: ::
try :
# Code that throws a java.lang.RuntimeException
except JavaException, ex :
if JavaException.javaClass() is java.lang.RuntimeException :
print "Caught the runtime exception : ", JavaException.message()
print JavaException.stackTrace()
if ex.javaClass() is java.lang.RuntimeException :
print "Caught the runtime exception : ", ex.message()
print ex.stacktrace()
Alternately, you can catch the REAL Java exception directly by using
the JException wrapper. ::
try :
# Code that throws a java.lang.RuntimeException
except jpype.JException(java.lang.RuntimeException), ex :
print "Caught the runtime exception : ", JavaException.message()
print JavaException.stackTrace()
print "Caught the runtime exception : ", ex.message()
print ex.stacktrace()
Known limitations
@@ -30,6 +30,7 @@
from . import nio
from . import reflect
from . import _refdaemon
from . import _classpath
_usePythonThreadForDaemon = False
@@ -60,14 +61,48 @@ def _initialize():
def isJVMStarted() :
return _jpype.isStarted()
def startJVM(jvm, *args):
Starts a Java Virtual Machine
def _hasClassPath(args):
for i in args:
if i.startswith('-Djava.class.path'):
return True
return False
:param jvm: Path to the jvm library file (, jvm.dll, ...)
:param args: Arguments to give to the JVM
def startJVM(jvm=None, *args, **kwargs):
Starts a Java Virtual Machine. Without options it will start
the JVM with the default classpath and jvm. The default classpath
will be determined by jpype.getClassPath(). The default JVM is
determined by jpype.getDefaultJVMPath().
jvm (str): Path to the jvm library file (, jvm.dll, ...)
default=None will use jpype.getDefaultJVMPath()
*args (str[]): Arguments to give to the JVM
classpath (Optional[string]): set the classpath for the jvm.
This will override any classpath supplied in the arguments
ignoreUnrecognized (Optional[bool]): option to jvm to ignore
invalid jvm arguments. (Default False)
_jpype.startup(jvm, tuple(args), True)
if jvm is None:
jvm = get_default_jvm_path()
# Check to see that the user has not set the classpath
# Otherwise use the default if not specified
if not _hasClassPath(args) and 'classpath' not in kwargs:
print("Use default classpath")
if 'ignoreUnrecognized' not in kwargs:
# Classpath handling
args = list(args)
if 'classpath' in kwargs and kwargs['classpath']!=None:
print("Set classpath")
_jpype.startup(jvm, tuple(args), kwargs['ignoreUnrecognized'])
# start the reference daemon thread
@@ -90,6 +90,7 @@ def __setattr__(self, attr, value):
raise AttributeError("%s does not have field %s"%(self.__name__, attr), self)
def _isIterable(obj):
if isinstance(obj, collections.Sequence):
return True
@@ -162,16 +163,19 @@ def _getClassFor(name):
def JArray(t, ndims=1):
if issubclass(t, _jwrapper._JWrapper):
if isinstance(t, (str,unicode)):
elif issubclass(t, _jwrapper._JWrapper):
t = t.typeName
elif isinstance(t, _JavaArray):
t = t.typeName
elif issubclass(t, _jclass._JAVAOBJECT):
elif isinstance(t, _jclass._JavaClass):
t = t.__name__
elif not isinstance(t, str) and not isinstance(t, unicode):
raise TypeError("Argument must be a java class, java array class, "
"java wrapper or string representing a java class")
Oops, something went wrong.

0 comments on commit 09ec730

Please sign in to comment.