I am trying to import my own java class into some jython code. I compiled my .java to a .class file and put the .class file into a .jar. I then include this .jar file using -Dpython.path="path/to/jar/my.jar". So far so good, no complaints when starting up my program.
However, when I get to the part of the code that uses my java class, it seems like it can't find any of the functions in my java class. I get the following AttributeError
:
AttributeError: 'pos.Test' object has no attribute 'getName'
Any suggestions would be much appreciated! (Code samples below.)
Java code:
package pos;
class Test{
private String name;
public Test(){
name = "TEST";
System.out.println( "Name = " + name );
}
public String getName(){
return name;
}
}
Jython code snippet:
import pos.Test
...
test = pos.Test()
print 'Name = ', test.getName()
It is about visibility. Your class is package-private. It will work if
python.security.respectJavaAccessibility = false
is added to the Jython registry. See https://www.jython.org/registry.html.
Or make the class public.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With