0

I m trying to launch the jemmy examples from https://jemmy.java.net/tutorial.html and keep getting the ClassNotFoundExeption about the test- class, what is given in org.netbeans.jemmy.Test.main(String params). For example, with

enter code here



import org.netbeans.jemmy.*;
import org.netbeans.jemmy.explorer.*;
import org.netbeans.jemmy.operators.*;

public class WaitWindowSample implements Scenario {

    public int runIt(Object param) {
        try { //start application 
            new ClassReference("org.netbeans.jemmy.explorer.GUIBrowser").startApplication();
            //wait frame 
            new JFrameOperator("GUI Browser");
        } catch (Exception e) {
            e.printStackTrace();
            return (1);
        }
        return (0);
    }

    public static void main(String[] argv) {
        String[] params = {"WaitWindowSample"};
        org.netbeans.jemmy.Test.main(params);
    }
} 

i get:

> Class WaitWindowSample does not exist!
java.lang.ClassNotFoundException: WaitWindowSample
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

I have a normal Netbeans (ant) project and added jemmy2.jar to project libraries. What can be wrong?

Xstian
  • 8,184
  • 10
  • 42
  • 72
Smer5
  • 96
  • 9

1 Answers1

-1

you should use classname with full package info. Try to use following code:

public static void main(String[] argv) {
    String[] params = {WaitWindowSample.class.getName()};
    org.netbeans.jemmy.Test.main(params);
}

I hope that it was worth to wait 9 months for this anwser :D

SunnyxD
  • 1
  • 1
  • It won't help. The class is declared by the user as outlined in the question. Probably declaring the class in a package, rather than the default package, will help. – Alexey Ivanov Oct 05 '16 at 16:36
  • I can agree with you only partially. Yes, it is true that author of this post could use other package than default, and it could be the main cause of this error. On the other hand, we do not know if he made it intentionally. Using WaitWindowSample.class.getName() instead of "WaitWindowSample" would avoid problems with packages, becouse it would return full name of class with packages – SunnyxD Oct 06 '16 at 14:10
  • In the case of default package, `WaitWindowSample.class.getName()` would return `"WaitWindowSample"` just as the question states. – Alexey Ivanov Oct 08 '16 at 09:15
  • Yes, in case of default package `WaitWindowSample.class.getName()` would return `WaitWindowSample`. For non default package f.eg. `package org.sample` it would return class with full package name, so it would be `org.sample.WaitWindowSample` .This would be solution for problem above, becouse developer doesn't have to put classpath as plain String. Have you tried to launch this code before commenting? – SunnyxD Oct 17 '16 at 17:18
  • No, I haven't actually. Now I tried, it works perfectly with the String. However, I used command line to compile and run rather than NetBeans IDE. It's enough to add `-cp jemmy.jar` when compiling with `javac`; but you have to include the location of `WaitWindowSample.class` to cp when running with `java`, otherwise it does not find the class: `java -cp .;jemmy.jar WaitWindowSample`. But still, it does not answer the original question. – Alexey Ivanov Oct 18 '16 at 07:26
  • I agree, *using `WaitWindowSample.class.getName()` is better*: if the class moves between packages, the code will continue to work without modifications. – Alexey Ivanov Oct 18 '16 at 07:44