0

I have got Marathon JAVA Driver to work in Eclipse and it works fine when I run the code from eclipse. However, When I export the project as runnable JAR file, and then execute the JAR file, I get the below error and the application is not launched.

at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:61) Caused by: java.lang.NullPointerException at net.sourceforge.marathon.javadriver.JavaProfile.(JavaProfile.java:205)

import java.io.IOException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import net.sourceforge.marathon.javadriver.JavaDriver;
import net.sourceforge.marathon.javadriver.JavaProfile;
import net.sourceforge.marathon.javadriver.JavaProfile.LaunchMode;
import net.sourceforge.marathon.javadriver.JavaProfile.LaunchType;

public class SwingAutomationSample {
    public static JavaDriver driver;
    public static JavaProfile profile;

@BeforeClass 
public void setUp() throws IOException {

        try {           
        profile = new JavaProfile(LaunchMode.EXECUTABLE_JAR);                   
        profile.setLaunchType(LaunchType.FX_APPLICATION);                
        profile.setExecutableJar("C:/Users/KarthikRaja/Desktop/Projects/xxyy.jar");
        profile.setWorkingDirectory("C:/Users/KarthikRaja/Desktop/Projects");      
        driver = new JavaDriver(profile);      
        }catch(Exception e) {
            System.out.println("java driver error ------------ " + e.toString());
        }
}

@Test
public void Form15CBFill() throws Exception {
    System.out.println("Inside Test Class");
    }
}```
  • I have made sure the JAR file is available in the specified location and also there are no permission issues, I have also executed as administrator – karthik110885 May 06 '21 at 14:31

2 Answers2

1

Marathon Java driver uses its jar files so that it can set JAVA_TOOL_OPTIONS. So it needs the jar file to be assessable in the file system.

Please check the JavaProfile.java line number 204 for reference.

For a quick fix export marathon jars and add them to class path and write a batch script to execute the test case.

Aditya Karra
  • 151
  • 1
  • 7
  • Thank you very much for update @aditya karra. I have tried to add the marathon jars in CLASSPATH variable and then executed the jar file from command line "java -jar automation.jar". However, am getting the same error. Should I do anything different when exporting my tests as executable JAR file from Eclipse. Thanks for your help. – karthik110885 May 11 '21 at 05:37
  • @karthik110885 Are marathon jars included in the automation jar? or they are separate jars? – Aditya Karra May 11 '21 at 05:50
  • thanks for the reply. They are included in automation jar as maven dependency, should I remove them? – karthik110885 May 11 '21 at 06:24
  • Don't pack them into a fat jar. Just extract support jars including marathon into a folder so that all jars are accessible in the file system. – Aditya Karra May 11 '21 at 06:31
  • @ Aditya thanks for the help. I have exported the jar now as an non-fat jar with all support jars extracted in to a sub-folder. Also, in manifest file, the classpath is pointed to the appropriate sub-folder. But , now am getting an "Caused by: java.lang.ClassNotFoundException" even though the referenced JAR and class file is available in the sub-folder. Should I be doing something different. Thanks again. – karthik110885 May 11 '21 at 07:34
  • @karthik110885 Can you just drop a mail to support team? – Aditya Karra May 11 '21 at 07:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232206/discussion-between-karthik110885-and-aditya-karra). – karthik110885 May 11 '21 at 07:39
  • Thanks for pointing me in the right direction. I will try some other methods and if not, I will drop a mail. Thanks again. – karthik110885 May 11 '21 at 07:58
1

@Aditya, again, thanks for pointing me in the right direction. The below steps solved the issue for me.

  1. Download selenium-standalone-jar and add it to the project build path
  2. As suggested by Aditya, export the project as runnable JAR file with option "copy required libraries into a sub-folder next to the generated JAR"
  3. In the exported JAR, make sure the manifest file includes the selenium-standalone-jar and other dependencies in the classpath

This resolved the issue for me.