Compile a new jar with foo method ?

Asked by Joe List

Hello,

I have a simple question. I just want to add a simple method in a Java
class of Sikuli. For example, add a foo method to Location.java

https://github.com/sikuli/sikuli/blob/develop/sikuli-script/src/main/java/org/sikuli/script/Location.java

My new method :
public Location foo(){
   return new Location(1, 1);
}

I see the prerequisite to compile Sikuli. But it's very complicated for me
(Visual C++, CMake, OpenCV, ...)

Prerequisite
https://github.com/sikuli/sikuli/blob/develop/build-win32.txt

Seems lot of stuff just to add a simple method to Location.java

I probably don't need all that stuffs, and also I currently don't know how
to use them :)

My question is finally simple: Is it possible to compile quickly a new jar
and use it in my python script ? What is the minimum software to use?

loc = Location(10,10)
loc.foo() # (1,1)

Thanks!

Question information

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

You can use the jar utility to unjar the sikuli-script.jar.

use the source class Location, modify it and compile it to a class file. The replace it in the unjared folder and rejar again.

But if you want to use such things in Python environment of Sikuli:

Just subclass Location, add your needs and use your Location subclass in your scripts.

Revision history for this message
Joe List (tribalddb3) said :
#2

Hello,

Thanks for your reply.
My problem is not completly resolved, it throw an error. I just try to explain exactly what I done. This is simple steps.

I just download jdk-7u2-windows-x64.exe to compile java class

I compile the Location.java to Location.class with

javac.exe path/to/Location.java

Works good.

I unjar sikuli-script.jar with winRAR
Just see it was possible here : http://siebelmantra.blogspot.com/2009/03/how-to-unjar-jar-file.html?showComment=1255521430693#c2260302387349205486

I overwrite the Location.class

I recreate the jar with:

jar.exe cfv sikuli-script.jar path/to/sikuli-script .

Works good

I overwrite the Sikuli X/sikuli-script.jar file

Launch my command

Sikuli-IDE.bat -s -r path/to/myproject.sikuli

And it throw an error in the terminal

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\__init__.py
", line 3, in <module>
  File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py",
 line 11, in <module>
java.lang.UnsupportedClassVersionError: org/sikuli/script/Location : Unsupported
 major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.privateGetPublicMethods(Unknown Source)

I need to compile the Location.java in a different way to works with Sikuli/JPython ?
What's wrong ?

Thanks again for your help

Revision history for this message
Joe List (tribalddb3) said :
#3

Hey,

I download the JDK 1.6
jdk-6u29-windows-x64.exe

I compile the class with the javac.exe from this SDK and it works perfectly !

loc = Location(10, 20)
print loc # (10,20)

loc2 = loc.foo()
print loc2 #(1,2)

So happy !
Thank you so much !
:)