Skip to content
\n

Java Class(User.java)

\n
package 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\n
\n

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.

\n

Execution command

\n
graalpy --jvm \\\n  --vm-cp=$CLASSPATH \\\n  ./main.py\n\n
\n

Error Message:

\n
User = java.type('com.example.model.User')\nKeyError: 'host symbol com.example.model.User is not defined or access has been denied'\n
\n

What I've Tried:

\n\n

Environment Details:

\n

GraalVM Version: Oracle GraalVM 23.0.1+11.1
\nGraalPy Version: GraalPy 3.10.8 (GraalVM CE JVM 23.1.2)
\nOperating System: macOS

\n

Questions:

\n","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

I tried your example and it printed Alice with no errors. What I did:

\n\n

The 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)?

","upvoteCount":0,"url":"https://github.com/oracle/graalpython/discussions/448#discussioncomment-11096667"}}}
Discussion options

You must be logged in to vote

I tried your example and it printed Alice with no errors. What I did:

  • Save your java code as com/example/model/User.java and your python code as main.py
  • javac com/example/model/User.java
  • graalpy --vm.cp=. main.py

The 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)?

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ShuzoShinagawa1102
Comment options

@msimacek
Comment options

Answer selected by msimacek
@ShuzoShinagawa1102
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants