Jython and JME

Hi, I was searching around and didn’t find much info on using Jython and JME together, only this one message by tspoon. http://www.java.net/node/675816

The example is old so i updated it, my first attempt failed when looking for some native libraries. I found these in ~/.jmonkeyplatform. Adding that path to sys.path is no help, os.chdir is not allowed either; the easy work around is just running the script from ~/.jmonkeyplatform. I assume there is a better way to setup the path so i moved forward.

The test below opens a black window, but fails with a java.lang.NullPointerException. http://pastebin.com/UDYrRBhe

Looks like the problem could be that the python method “simpleInitApp” is never called. “simpleUpdate” is also never called. If i call simpleInitApp directly, it complains there is no self.display attribute.

Maybe subclassing jme.app.SimpleApplication is not the best way to do this?


import os, sys

JMONKEY_ROOT = ‘/usr/local/jmonkeyplatform’

#os.chdir( os.path.expanduser(’~/.jmonkeyplatform’) ) # not allowed in jython

if ‘java’ in sys.platform.lower():

print(‘hello jython’)

path = os.path.join(os.path.join(JMONKEY_ROOT,‘jmonkeyplatform’),‘libs’)

for file in os.listdir(path):

if file.endswith(’.jar’):

sys.path.append( os.path.join( path, file ) )

print( ‘adding: %s’ %file )

import com.jme3 as jme

vec = jme.math.Vector3f

class MyGame( jme.app.SimpleApplication ):

def init(self):


def simpleInitApp(self):

self.display.setTitle(‘jme using Jython’)

sphere = jme.scene.shape.Sphere( ‘mysphere’, 60, 50, 25 )

sphere.setLocalTranslation( vec(0,0,-40) )

geom = jme.scene.Geometry( ‘sphere’, sphere )

self.rootNode.attachChild( geom )

print(‘simple init game complete’)

def simpleUpdate(self):


test = MyGame()

test.start() # opens thread, non-blocking

while True: pass # wait for thread