Jar file is not executing after successfully generating .jar file of maven project

Trying to generate .jar file of my maven project, so i tried two methods but both are getting fail:

  1. I am adding a Runnable class inside Test package(Using TestNG classes)
  2. Inside the Runnable class, there is a reference of which class i want to execute.
  3. Then i am generating executable jar file. Now when i am trying to run it by simply double click on it, nothing is happening. I tried to run it by command prompt but it is showing test case skipped and it is showing configuration failure.

I tried to generate jar file by adding maven plugin inside the pom file but when i am executing the jar file, it is showing an error that Mainclass is missing.

Where am i doing wrong, please suggest some solutions.

3 Likes

Hi @bucksbunny11,

For the skipped test issue you are having with the testng. I am assuming that you are calling direct driver setup class without the main method instead of testng xml file. You are getting the skipped message due to driver setup class invoked by the testng file. So, from your Runnable class you need to call testng suite file instead of the driver setup call.

For the 2nd query you are having the jar file the mainclass There could be two reasons the Manifest file path is not reachable in your project. Or within your POM file the main file name is not correct. For ex:- org.apache.maven.plugins maven-jar-plugin 3.1.0

                            <!-- give full qualified name of your main class-->
                            <mainClass>TestRunner.java</mainClass>

                        </manifest>
                    </archive>
                </configuration>

            </plugin>

Here is the Manifest file as well.

Manifest-Version: 1.0 Main-Class: TestRunner

You can find more information in the sample suite. https://drive.google.com/file/d/1Ag0CsFImSAHl13Mb2toim2XQCFTISqZg/view?usp=sharing

1 Like

Thanks for reaching, so i need to add the testng.xml as suite in runnable class? But my testng file is not calling any class(i did not made any changes, self built).

And for manifest file, i just need to add a folder in the java project and add that file, right?

@bucksbunny11 Thanks for the response. According to your testng file it’s calling the liveContract file which must be having the testng annotation like @BeforeTest @Test @AfterTest. So yes in the you need to call the testng xml file in your main Runner Class.

    public class TestRunner {


    public static void main(String[] args) throws Exception {

        TestNG runner= new TestNG();

        List<String> suites = new ArrayList<>();
        suites.add("path of testng xml suite file");
        runner.setTestSuites(suites);
        runner.run();
    }
} 

Here is the sample for calling the testng suite.

For the the Manifest file. It’s should be creating automatically when you are converting your test suite in JAR. Although, if it’s not you can add the manifest file in your test suite folder.