how to run java source program in command prompt

Asked by Vaishali

hi..
I have written a simple sikuli java program in notepad.. bt i m not able to run it using cmd prompt.. As i m new to it.. can u pls explain me how to run it..

Question information

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

You should use NetBeans or Eclipse, when programming in Java - this would solve all your problems.

Java source code has to be compiled into a class file using javac compiler (which is only available in the Java JDK). The compiled class then can be run with the java command.

Revision history for this message
Vaishali (vaishoo-vasu) said :
#2

I did the same.. Getting this error while running it..
C:\Program Files\Sikuli X>java -jar sikuli-script.jar HelloWorld
[error] Can't run this Sikuli script: HelloWorld
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(Unknown Source)
        at org.sikuli.script.ScriptRunner.getPyFrom(ScriptRunner.java:106)
        at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:100)
        at org.sikuli.script.SikuliScript.main(SikuliScript.java:111)

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

Uuups, things are messed up a little bit:

So I guess your "simple sikuli java program in notepad" is a Sikuli script like this:

find("some_image.png")
click("some_other_image.png")
...

which is Jython/Python language (not Java).

When I am right, then you have to name your script:
HelloWorld.py

and wrap it into a folder
HelloWorld.sikuli

together with the images, that might be used in the script.

to run this:
C:\Program Files\Sikuli X>java -jar sikuli-script.jar -r HelloWorld.sikuli

If I am not right, and it is really a Java program, then my comment #1 is applicable and the final usage would be:
C:\Program Files\Sikuli X>java -cp sikuli-script.jar HelloWorld

putting sikuli-script.jar on the class path and running the compiled class file HelloWorld.

Revision history for this message
Vaishali (vaishoo-vasu) said :
#4

Actually this is my code.. when i run it using eclipse it runs properly... when i try to run it in cmd prompt i get those errors.. ya its a simple program i hav just to started learning..

import org.sikuli.script.*;
public class HelloWorldClass {

 public static void main(String[] args)
  {
  float similarity=(float)0.7;
  int timeout=5;
  Pattern Win7StartButton =new Pattern("C:/Users/404905/workspace/HelloWorld/image/Win7StartButton.png");
  Screen screen=new Screen();
  if(screen.exists(Win7StartButton.similar(similarity),timeout)!=null)
   {
   try
   {
       screen.click(Win7StartButton,0);
       screen.type("hello");
       Pattern image =new Pattern("C:/Users/404905/workspace/HelloWorld/image/image.png").similar(similarity);
       screen.click(image);
      }
     catch(FindFailed e)
      {
         e.printStackTrace();
      }
      }

     }
}

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

Sorry, but this is basic Java programming using Eclipse:

You have to build a jar file in Eclipse, that then is used on command line

java -cp sikuli-script.jar -jar myApp.jar

or you run the compiled java class HelloWorldClass from the projects target path.

Revision history for this message
Vaishali (vaishoo-vasu) said :
#6

ThankU