1
- # Jython Compatibility
1
+ # Jython Migration Guide
2
2
3
3
Most Jython code that uses Java integration will be based on a
4
4
stable Jython release, and these only come in Python 2.x versions.
5
5
GraalVM's Python runtime, in contrast, is only targeting Python 3.x.
6
6
Thus, GraalVM does not provide full compatibility with these earlier 2.x versions of Jython.
7
7
8
- Nonetheless, there are certain features of Jython's Java integration that we can offer similarly.
9
- Here is an example:
8
+ Thus, a significant migration step will have to be to migrate all your code to
9
+ Python 3. For Jython specific features, follow this document to learn about
10
+ migration to GraalVM's Python runtime.
11
+
12
+ Be adviced: some features of Jython have a negative impact on runtime
13
+ performance, and thus are disabled by default. To make migration easier, we
14
+ enable some features with a command line flag on GraalVM:
15
+ ` --python.EmulateJython ` .
16
+
17
+ ### Importing
18
+ There are certain features of Jython's Java integration that we also offer. Here
19
+ is an example:
10
20
11
21
>>> import java.awt as awt
12
22
>>> win = awt.Frame()
@@ -16,24 +26,23 @@ Here is an example:
16
26
'java.awt.Dimension[width=200,height=200]'
17
27
>>> win.show()
18
28
19
- This example works exactly the same on both Jython and Python on GraalVM.
20
- Some features of Jython are more expensive at runtime, and thus are hidden behind a
21
- command line flag on GraalVM: ` --python.EmulateJython ` .
22
-
23
- ## Import Java Classes
24
-
25
- Import statements allow you to import Java classes, but (unlike Jython), only
26
- packages in the ` java ` namespace can be directly imported.
29
+ This example works exactly the same on both Jython and Python on
30
+ GraalVM. However, on GraalVM only packages in the ` java ` namespace can be
31
+ directly imported. Importing classes from packages outside ` java ` namespace also
32
+ requires the ` --python.EmulateJython ` option to be active.
27
33
28
- For example, this will work:
29
- ``` python
34
+ Additionally, importing Java packages as Python modules is only supported under
35
+ very specific circumstances. This will work:
36
+ ```
30
37
import java.lang as lang
31
38
```
39
+
32
40
But this will not:
33
41
``` python
34
42
import javax.swing as swing
35
43
from javax.swing import *
36
44
```
45
+
37
46
Instead, you will have to import one of the classes you are interested in directly:
38
47
``` python
39
48
import javax.swing.Window as Window
0 commit comments