Compile Issue with Jython, java context

Asked by Jan

Hi, could you please assist.

When using

I tried from sikuli import * and did not get any errors, however as I want to use Sikuli in a jython program I used, as recommended:

import org.sikuli.script.SikulixForJython
from sikuli import *

I receive the following error:
[error] RunTimeINIT: *** terminating: no valid Java context for SikuliX available (java.security.CodeSource.getLocation() is null

I set the path to sikuliapi with
sys.append

The program works flawlessly in Eclipse, however after moving to command line I started getting this error.
When I put the sikuliapi on the classpath, Sikuli is not found. My Java also seems to be working correctly as java -jar is recognized when I type it into command prompt.

I am using jython mymodule.py currently when compiling as I am trying to test my modules. I am compiling non sikuli modules flawlessly, only modules with import org.sikuli are giving me this issue. I have tried it on multiple computers.

I am not sure what I am doing wrong, I have run through the forum, but changing the class path isn't working, I even tried dropping Sikulixapi into the java and later on jythonpaths.

This was also attempted

os.environ['classpath'] = path to sikuli

os.environ['CLASSPATH'] = path to sikuli

os.environ['JYTHONPATH'] = path to sikuli

os.environ['PYTHONPATH'] = path to sikuli

-D.python = path to sikuli also didn't do the trick.

os.environ['JAVAPATH'] = path to sikuli could not be done as a result of key errors

*I am using Windows 7 & 8
Regards

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

You have to put the path to the sikuli jar into the system environment before starting Jython.

hence you cannot do that inside your script, but in your commandfile, that starts you Jython workflow.

Revision history for this message
Jan (sikulinewbi) said :
#2

Thank you for the quick response.

I removed the sys.environ commands from my module additionally I noticed that the variables on the computer I am using had some issues.

This fixed my issue, it seem like:

set classpath = ...
did not pull through the values, I ran a setx script setting a blank classpath and then set classpath = sikuli path

-I had to run two seperate scripts for the set, as the environment does not update the variables once set, it only found sikuli after doing it this way.

There is a bug with jython where if the java paths are mixed up, this error will occur:

-This seems to happen if Sikuli is added in PATH rather than CLASSPATH, this is just some additional info I picked up while solving this issue.

File "<string>", line 444, in <module> File "<string>", line 435, in main File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess", line 522, in call File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess", line 710, in __init__ File "Z:\jythondev\jython27\src\shell\build\jython\out00-PYZ.pyz\subprocess", line 958, in _execute_child

I haven't tried this with PYTHONPATH yet, but my scripts are running now.

Thank you once again for the advice

Revision history for this message
Jan (sikulinewbi) said :
#3

One more note:

In the classpath I also added sikuli.jar/Lib , I had inconsistency with finding sikuli if this was not included

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Take care: sikuli.jar must be on java classpath, not sikuli.jar/Lib

... and you might try the latest version of SikuliX:
https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming

start here:
http://sikulix.com