1- # scyjava
2-
31Supercharged Java access from Python.
42
5- Built on [ pyjnius ] ( https://pyjnius .readthedocs.io/en/latest/ ) and [ jgo] ( https://github.com/scijava/jgo ) .
3+ Built on [ JPype ] ( https://jpype .readthedocs.io/en/latest/ ) and [ jgo] ( https://github.com/scijava/jgo ) .
64
75## Use Java classes from Python
86
97``` python
10- >> > import scyjava, jnius
11- >> > System = jnius.autoclass(' java.lang.System' )
8+ >> > import jpype
9+ >> > import jpype.imports
10+ >> > jpype.startJVM()
11+ >> > System = jpype.JClass(' java.lang.System' )
1212>> > System.getProperty(' java.version' )
13- ' 1.8.0_152-release '
13+ ' 1.8.0_252 '
1414```
1515
1616To pass parameters to the JVM, such as an increased max heap size:
1717
1818``` python
19- >> > import scyjava_config
20- >> > scyjava_config.add_options(' -Xmx6g' )
21- >> > import scyjava, jnius
22- >> > Runtime = jnius.autoclass(' java.lang.Runtime' )
19+ >> > import jpype
20+ >> > import jpype.imports
21+ >> > import scyjava.jvm
22+ >> > scyjava.jvm.start_JVM(' -Xmx6g' )
23+ >> > Runtime = jpype.JClass(' java.lang.Runtime' )
2324>> > Runtime.getRuntime().maxMemory() / 2 ** 30
24255.33349609375
2526```
2627
27- See the [ Pyjnius documentation] ( https://pyjnius .readthedocs.io/en/latest/ ) for more about calling Java from Python.
28+ See the [ JPype documentation] ( https://jpype .readthedocs.io/en/latest/ ) for more about calling Java from Python.
2829
2930## Use Maven artifacts from remote repositories
3031
3132### From Maven Central
3233
3334``` python
34- >> > import sys; sys.version_info
35+ >> > import sys
36+ >> > sys.version_info
3537sys.version_info(major = 3 , minor = 6 , micro = 5 , releaselevel = ' final' , serial = 0 )
3638>> > import scyjava_config
3739>> > scyjava_config.add_endpoints(' org.python:jython-standalone:2.7.1' )
38- >> > import scyjava, jnius
39- >> > jython = jnius.autoclass(' org.python.util.jython' )
40+ >> > import jpype
41+ >> > import scyjava.jvm
42+ >> > scyjava.jvm.start_JVM()
43+ >> > jython = jpype.JClass(' org.python.util.jython' )
4044>> > jython.main([])
41- Jython 2.7 .1 (default:0df7adb1b397 , Jun 30 2017 , 19 :02 :43 )
42- [OpenJDK 64 - Bit Server VM (JetBrains s.r.o )] on java1.8.0_152 - release
45+ Jython 2.7 .1 (default:0df7adb1b397 , Jun 30 2017 , 19 :02 :43 )
46+ [OpenJDK 64 - Bit Server VM (AdoptOpenJDK )] on java1.8.0_252
4347Type " help" , " copyright" , " credits" or " license" for more information.
44- >> > import sys; sys.version_info
48+ >> > import sys
49+ >> > sys.version_info
4550sys.version_info(major = 2 , minor = 7 , micro = 1 , releaselevel = ' final' , serial = 0 )
4651```
4752
@@ -51,13 +56,18 @@ sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)
5156>> > import scyjava_config
5257>> > scyjava_config.add_repositories({' scijava.public' : ' https://maven.scijava.org/content/groups/public' })
5358>> > scyjava_config.add_endpoints(' net.imagej:imagej:2.0.0-rc-65' )
54- >> > import scyjava, jnius
55- >> > System = jnius.autoclass(' java.lang.System' )
59+ >> > import scyjava.jvm
60+ >> > import jpype
61+ >> > import jpype.imports
62+ >> > from jpype import JClass, JArray, JLong
63+ >> > scyjava.jvm.start_JVM()
64+ >> > System = JClass(' java.lang.System' )
5665>> > System.setProperty(' java.awt.headless' , ' true' )
57- >> > ImageJ = jnius.autoclass (' net.imagej.ImageJ' )
66+ >> > ImageJ = JClass (' net.imagej.ImageJ' )
5867>> > ij = ImageJ()
5968>> > formula = " 10 * (Math.cos(0.3*p[0]) + Math.sin(0.3*p[1]))"
60- >> > blank = ij.op().create().img([64 , 16 ])
69+ >> > dims = JLong[64 , 16 ]
70+ >> > blank = ij.op().getClass().getMethod(' create' ).invoke(ij.op()).img(dims)
6171>> > sinusoid = ij.op().image().equation(blank, formula)
6272>> > print (ij.op().image().ascii(sinusoid))
6373,,,-- + oo****** oo+ -- ,,,,,-- + oo****** o++-- ,,,,,-- + oo****** o++-- ,,,
@@ -85,16 +95,19 @@ See the [jgo documentation](https://github.com/scijava/jgo) for more about Maven
8595# ## Convert Java collections to Python
8696
8797```python
88- >> > import scyjava, jnius
89- >> > System = jnius.autoclass(' java.lang.System' )
98+ >> > import jpype
99+ >> > import jpype.imports
100+ >> > import scyjava
101+ >> > import scyjava.jvm
102+ >> > scyjava.jvm.start_JVM()
103+ >> > import scyjava.convert
104+ >> > System = jpype.JClass(' java.lang.System' )
90105>> > props = System.getProperties()
91106>> > props
92- < java.util.Properties at 0x 10dc2daf0 jclass= java/ util/ Properties jself= < LocalRef obj= 0x 7fcfefd34b20 at 0x 10dc371f0 > >
107+ < java object ' java. util. Properties' >
93108>> > [k for k in props]
94- Traceback (most recent call last):
95- File " <stdin>" , line 1 , in < module>
96- TypeError : ' java.util.Properties' object is not iterable
97- >> > [k for k in scyjava.to_python(props) if k.startswith(' java.vm.' )]
109+ [' java.runtime.name' , ' sun.boot.library.path' , ' java.vm.version' , ' java.vm.vendor' , ' java.vendor.url' , ' path.separator' , ' java.vm.name' , ' file.encoding.pkg' , ' user.country' , ' sun.os.patch.level' , ' java.vm.specification.name' , ' user.dir' , ' java.runtime.version' , ' java.awt.graphicsenv' , ' java.endorsed.dirs' , ' os.arch' , ' java.io.tmpdir' , ' line.separator' , ' java.vm.specification.vendor' , ' os.name' , ' sun.jnu.encoding' , ' java.library.path' , ' java.specification.name' , ' java.class.version' , ' sun.management.compiler' , ' os.version' , ' user.home' , ' user.timezone' , ' java.awt.printerjob' , ' file.encoding' , ' java.specification.version' , ' java.class.path' , ' user.name' , ' java.vm.specification.version' , ' java.home' , ' sun.arch.data.model' , ' user.language' , ' java.specification.vendor' , ' awt.toolkit' , ' java.vm.info' , ' java.version' , ' java.ext.dirs' , ' sun.boot.class.path' , ' java.vendor' , ' file.separator' , ' java.vendor.url.bug' , ' sun.io.unicode.encoding' , ' sun.cpu.endian' , ' sun.desktop' , ' sun.cpu.isalist' ]
110+ >> > [k for k in scyjava.convert.to_python(props) if k.startswith(' java.vm.' )]
98111[' java.vm.version' , ' java.vm.vendor' , ' java.vm.name' , ' java.vm.specification.name' , ' java.vm.specification.vendor' , ' java.vm.specification.version' , ' java.vm.info' ]
99112```
100113
@@ -108,26 +121,25 @@ TypeError: 'java.util.Properties' object is not iterable
108121Traceback (most recent call last):
109122 File " <stdin>" , line 1 , in < module>
110123AttributeError : ' list' object has no attribute ' stream'
111- >> > scyjava.to_java(squares).stream()
112- < java.util.stream.Stream at 0x 119d8ba40 jclass = java/ util/ stream/ Stream jself = < LocalRef obj = 0x 7fcfefd34810 at 0x 10dc37810 > >
124+ >> > scyjava.convert. to_java(squares).stream()
125+ < java object ' java. util. stream.ReferencePipeline.Head ' >
113126```
114127
115128# ## Introspect Java classes
116129
117130```python
118- >> > import scyjava
119- >> > NumberClass = scyjava.jclass(' java.lang.Number' )
131+ >> > NumberClass = scyjava.convert.jclass(' java.lang.Number' )
120132>> > NumberClass
121- < Class at 0x 10dca89e8 jclass = java/ lang / Class jself = < LocalRef obj = 0x 7fcfefd33420 at 0x 10dc37a30 > >
133+ < java object ' java.util.stream.ReferencePipeline.Head ' >
122134>> > NumberClass.getName()
123135' java.lang.Number'
124- >> > NumberClass.isInstance(scyjava.to_java(5 ))
136+ >> > NumberClass.isInstance(scyjava.convert. to_java(5 ))
125137True
126- >> > NumberClass.isInstance(scyjava.to_java(' Hello' ))
138+ >> > NumberClass.isInstance(scyjava.convert. to_java(' Hello' ))
127139False
128140```
129141
130- ## Available functions
142+ # # Available functions -- EE fix this
131143
132144```
133145>> > import scyjava
0 commit comments