Problem when build test with Eclipse/Maven/TestNG, NoClassDefFoundError

Asked by DH

So I've tried and I've tried for a week now but I can't get it to work. I'm sorry. I've red many FAQs here on launchpad, but I really cant get it to work. Heres is my problem:
I have a Maven project in Eclipse with TestNG and Sikuli. When I run the test as Run as -> TestNG Test it works just fine. But when i run the test as Run as -> Maven test, I get this error: java.lang.NoClassDefFoundError: org/sikuli/script/FindFailed

Here is some info regarding config etc etc:

Sikuli version = SikuliX Setup Build: 1.0.1

And here is how my Java environment looks like:
Java version:
C:\Sikuli X>java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) Client VM (build 24.55-b03, mixed mode, sharing)

Java installed under:
C:\Program Files (x86)\Java\jdk1.7.0_55

Path looks like this:
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Sikuli X\Sikuli-IDE\libs;%JAVA_HOME%\bin;

%SIKULI_HOME% = C:\Sikuli X\Sikuli-IDE
%JAVA_HOME% = C:\Program Files (x86)\Java\jdk1.7.0_55

http://s1048.photobucket.com/user/AutomatedTester/media/Img01_zpsfa634796.png.html?filters[user]=140045205&filters[recent]=1&sort=1&o=2

Here is my configuration in Eclipse:

http://s1048.photobucket.com/user/AutomatedTester/media/Img02_zpsa09f4c62.png.html?filters[user]=140045205&filters[recent]=1&sort=1&o=0

http://s1048.photobucket.com/user/AutomatedTester/media/Img03_zpsd948fd85.png.html?filters[user]=140045205&filters[recent]=1&sort=1&o=1

Test-case
package com.KvadratTest.KvadratTest;

import org.testng.Assert;
import org.testng.annotations.Test;

public class NewTest {

  @Test
  public void LoginValidUser() {

  LoginPage lp = new LoginPage();
  boolean vs = lp.ValidUser("test", "test");

  Assert.assertEquals(vs, true);
 }
}

Test-class
package com.KvadratTest.KvadratTest;

import org.sikuli.script.App;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Key;
import org.sikuli.script.Screen;
import org.sikuli.script.*;

public class LoginPage {

 private Screen _s;
 private String NPath = "C:\\Users\\AutoTester\\AppData\\Roaming\\Test\\test.exe";

 public LoginPage()
 {
  Screen s = new Screen();
  this._s = s;
 }

 public Boolean ValidUser(String user, String password)
 {

  try
   {

    App.open(NPath);
    _s.wait("imgs/User.png", 10);
    _s.type(user);
    _s.click("imgs/Password.png", 0);
    _s.type(password);
    _s.click("imgs/Login.png", 0);
    _s.wait("imgs/Validuser.png", 10);
    _s.click("imgs/FileClient.png");
    _s.wait("imgs/LogoutUser.png", 5);
    _s.click("imgs/LogoutUser.png");
    _s.click("imgs/ExitLogin.png");
    return true;

   }
    catch(FindFailed e)

   {
   e.printStackTrace();
   }
  return false;
 }

Error in Maven Console:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test (default-test) on project KvadratTest: There are test failures.

http://s1048.photobucket.com/user/AutomatedTester/media/Img04_zpsb972ac4a.png.html?filters[user]=140045205&filters[recent]=1&sort=1&o=3

So I really need help with this, I'm stuck :(

Question information

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

--1: path to Sikuli stuff should not contain blanks.
recommended: c:\SikuliX

--2. when using java, it is recommended to use sikuli-java.jar not sikuli-ide.jar (setup option 4)

--3. a SIKULI_HOME is not needed for version 1.0.1+

--4. everything needed for RC3 should be purged from environment.

--5. when running Maven, you need an adequate dependency to sikuli-jav.jar in your pom.

Revision history for this message
DH (dh72) said :
#2

Sorry RaiMan,
forgot my POM-file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.KvadratTest</groupId>
  <artifactId>KvadratTest</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>KvadratTest</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
  <groupId>org.testng</groupId>
  <artifactId>testng</artifactId>
  <version>6.1.1</version>
  <scope>test</scope>
    </dependency>
<dependency>
 <groupId>org.sikuli</groupId>
 <artifactId>sikuli-core</artifactId>
 <version>1.1.3</version>
</dependency>

  </dependencies>

</project>

Revision history for this message
DH (dh72) said :
#3

Ok,
1. I changed my foldername to SikuliX
2. I downloaded sikuli-java.jar
3. Deleted the old reference to sikuli-ide.jar and replaced it with sikuli-java.jar in Eclipse (Referenced Libraries/sikuli-java.jar)
4. Changed my Path = C:\SikuliX\sikuli-java\libs

And then:

Took Project -> Clean...
Run as -> Maven test

Same error as before.

What did you mean with: "--4. everything needed for RC3 should be purged from environment."?

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

<dependency>
 <groupId>org.sikuli</groupId>
 <artifactId>sikuli-core</artifactId>
 <version>1.1.3</version>
</dependency>

This is not sikuli-java.jar (not on Maven Central yet). This is the Sikuli Java API from https://code.google.com/p/sikuli-api/, which is not Java API compatible.

--- "--4. everything needed for RC3 should be purged from environment."
I am talking about Sikuli X-1.0rc3 the predecessor of SikuliX version 1.0.1.

Revision history for this message
DH (dh72) said :
#5

Ok, so how should my Pom look like?
I visited http://www.sikulix.com/quickstart.html but couldn't get more ino from there, sorry.

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

You either have to add sikuli-java.jar manually to your local repository or use a directory based dependency.

Revision history for this message
DH (dh72) said :
#7

Thanks för your answer again :-)

I tried this:

<dependency>
 <groupId>org.sikuli</groupId>
 <artifactId>sikuli-core</artifactId>
 <version>1.1.3</version>
 <scope>system</scope>
 <systemPath>${basedir}/lib/sikuli-java.jar</systemPath>
</dependency>

1. I created a new folder in my Maven project, copied sikuli-java.jar and its lib-folder
2. Made a new "Add jar" to /lib/sikuli-java.jar (in my project)
3. Maven clean and new build
4. Run my Maven test
5. Same still error

:-(

Revision history for this message
DH (dh72) said :
#8

RaiMan, I made it work thanks to your help :-)

How? Well when I tried to execute my test via TestNG (that worked prevoius), it didn't work! I received an error message from Sikuli that told me to reboot the system thanks to path-changes.

So I did (as you told me) and voiilaaa!

Now I can build my test via Maven :-)

Thanks again for your help :-)