Java Class(User.java)
\npackage com.example.model;\n\npublic class User {\n\n private String name;\n\n public User(String name) {\n this.name = name;\n }\n\n public String getName() {\n return this.name;\n }\n}\n\nI've compiled the Java class and packaged it into a JAR file named gpdemo-0.0.1-SNAPSHOT-plain.jar, and I set it as classpath for zshrc.
\nExecution command
\ngraalpy --jvm \\\n --vm-cp=$CLASSPATH \\\n ./main.py\n\nError Message:
\nUser = java.type('com.example.model.User')\nKeyError: 'host symbol com.example.model.User is not defined or access has been denied'\nGraalVM Version: Oracle GraalVM 23.0.1+11.1
\nGraalPy Version: GraalPy 3.10.8 (GraalVM CE JVM 23.1.2)
\nOperating System: macOS
I tried your example and it printed Alice with no errors. What I did:
com/example/model/User.java and your python code as main.pyjavac com/example/model/User.javagraalpy --vm.cp=. main.pyThe differences I have from you is that I used the latest release, I'm on Linux and I didn't build a JAR. Could you please try the latest release (24.1.1, the graalpy-jvm variant)?
-
|
Hello everyone, What I want to doI'm trying to access a Java class from a Python script using GraalPy (GraalPython) with GraalVM, but I'm encountering an error that I can't seem to resolve. Python Script (main.py) Java Class(User.java) I've compiled the Java class and packaged it into a JAR file named gpdemo-0.0.1-SNAPSHOT-plain.jar, and I set it as classpath for zshrc. Execution command Error Message: What I've Tried:
Environment Details:GraalVM Version: Oracle GraalVM 23.0.1+11.1 Questions:
|
Beta Was this translation helpful? Give feedback.
-
|
additionally, here is the contained classes which are showed by |
Beta Was this translation helpful? Give feedback.
-
|
Hi @ShuzoShinagawa1102, the option for supplying classpath when running through the graalpy launcher is |
Beta Was this translation helpful? Give feedback.
I tried your example and it printed
Alicewith no errors. What I did:com/example/model/User.javaand your python code asmain.pyjavac com/example/model/User.javagraalpy --vm.cp=. main.pyThe differences I have from you is that I used the latest release, I'm on Linux and I didn't build a JAR. Could you please try the latest release (24.1.1, the
graalpy-jvmvariant)?