Eclipse No Class def found - Loadrunner lr.class

1.9k views Asked by At

We wanted to run Junit Test in Loadrunner and below is the code written in eclipse: When i run the code in eclipse i get NoClassDefFoundError Exception. From Loadrunner Vugen Folder I zipped the "lr.class" file and imported it in the eclipse Jar libraries.

import classes.lrapi.lr;
import org.junit.Test;

public class Jtst {


@Test



public void tst() {
    System.out.println("Tst method");
        try{            

lr.start_transaction("T11");
//lr.start_transaction("T1");
System.out.print("Executing...");

lr.end_transaction("T1",lr.PASS);
    }catch (Exception e){
        e.printStackTrace();
    }
}

public static void main(String args[]) throws ClassNotFoundException
{
    System.out.println("Main");
    Jtst j1 = new Jtst();   

    j1.tst();

}
}

When i run the program I get the Exception NoClassDefFoundError Please find below the error message.

java.lang.NoClassDefFoundError: lrapi/lr
    at Jtst.tst(Jtst.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run
1

There are 1 answers

0
e-Dough On

The easyest way to add a references to LoadRunner API is by using LoadRunner developer's add-in.

To use it (from LoadRunner user guide):

  1. Make sure you have JDK 1.7 (JRE 7) on your machine. Go to oracle.com to check your version or download the required version. After you install it, open Eclipse and select Window > Preferences. Navigate to the Java > Installed JREs node. If jre7 is not in the Installed JREs list, click Add and use the wizard to add its folder (for example c:\Program Files\Java\jre7). In the Installed JREs list, click the check box by jre7 to instruct Eclipse to use this version.
  2. Run the Eclipse Dev add-in, LREclipseIDEAddInDevSetup.exe, from the download/DVD folder: Additional Components\IDE Add-Ins Dev. After installing the Eclipse add-in, rebuild the plugin cache by running the following command line string: Eclipse.exe -clean.
  3. In Eclipse, open your Selenium or JUnit test.
  4. Code the test as you normally would in Eclipse.
  5. Build your java classes.
  6. Select Devops Vuser > Add LoadRunner API Reference to add the desired LoadRunner functions to your script as well as transactions, rendezvous points, and messages.