Message1553
I have a small Jython test project in PyDev with structure:
src
bpkg
__init__.py
AltB.py
B.py
NonClassCode.py
From this I wish to run jythonc to create a jar file, b.jar. Note that B.py uses a Java class A in a.jar.
AltB.py is as follows (also attached):
********************************
from NonClassCode import MyFunction
class AltB:
def __init__(self):
pass
def giveGreeting(self, greeting):
"@sig public java.lang.String giveGreeting(java.lang.String greeting)"
MyFunction(greeting + " from AltB")
return "MyFunction called OK"
if __name__ == '__main__':
b = AltB()
b.giveGreeting("Hello")
********************************
NonClassCode.py is:
********************************
def MyFunction(greeting):
print greeting
********************************
I have set classpath to include a.jar. When I run jythonc, I get this output:
processing __init__
processing AltB
processing bpkg.NonClassCode
processing B
Note that I have tried "from bpkg.NonClassCode import MyFunction" in AltB.py, but it seems to have no effect. As this message suggests, NonClassCode.java is placed in .../jpywork/bpkg/bpkg. Note that if NonClassCode is not imported, it isn't placed in the wrong directory.
The jar file created, b.jar, has AltB in it but the method giveGreeting isn't visible. From a Java project I can create an instance of AltB, but I cannot call the method. Looking at the generated Java code, there is no public method.
This is in contrast to the following class B (in B.py):
********************************
import java
from com.ge.research.test import A
class B(java.lang.Object):
def __init__(self):
pass
def sayHello(self, a):
"@sig public java.lang.String sayHello(com.ge.research.test.A a)"
return a.sayHello()
if __name__ == '__main__':
b = B()
a = A()
b.sayHello(a)
*********************************
This generates Java code with a public method sayHello which I can call from Java code that imports AltB from b.jar.
I have not discovered the pattern of when this works as I would expect and when it does not. If there is a way to get consistent behavior please let me know.
|
|
Date |
User |
Action |
Args |
2008-02-20 17:17:47 | admin | link | issue1693847 messages |
2008-02-20 17:17:47 | admin | create | |
|