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
- Thus, GraalVM does not provide full compatibility with these earlier 2.x versions of Jython.
6
+ GraalVM does not provide a full compatibility with these earlier 2.x versions of Jython.
7
+ Thus, a significant migration step will have to be taken to migrate all your code to Python 3.
7
8
8
- Nonetheless, there are certain features of Jython's Java integration that we can offer similarly.
9
+ For Jython specific features, follow this document to learn about migration to GraalVM's Python runtime.
10
+
11
+ Note that some features of Jython have a negative impact on runtime performance, and are disabled by default.
12
+ To make migration easier, you can enable some features with a command line flag on GraalVM: ` --python.EmulateJython ` .
13
+
14
+ ## Importing Java Packages
15
+
16
+ There are certain features of Jython's Java integration that are enabled by default on GraalVM's Python runtime.
9
17
Here is an example:
10
18
11
19
>>> import java.awt as awt
@@ -17,23 +25,21 @@ Here is an example:
17
25
>>> win.show()
18
26
19
27
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.
28
+ However, on GraalVM only packages in the ` java ` namespace can be directly imported.
29
+ Importing classes from packages outside the ` java ` namespace also requires the ` --python.EmulateJython ` option to be active.
27
30
31
+ Additionally, importing Java packages as Python modules is only supported under very specific circumstances.
28
32
For example, this will work:
29
33
``` python
30
34
import java.lang as lang
31
35
```
36
+
32
37
But this will not:
33
38
``` python
34
39
import javax.swing as swing
35
40
from javax.swing import *
36
41
```
42
+
37
43
Instead, you will have to import one of the classes you are interested in directly:
38
44
``` python
39
45
import javax.swing.Window as Window
0 commit comments