how to create an executable file [jar] for selenium testng maven project which dont have a main class

4,143 views
Skip to first unread message

Nidhish Narayana

unread,
Sep 12, 2014, 4:56:30 AM9/12/14
to testng...@googlegroups.com
I have a Selenium TestNG project created with maven. ``

There is no main class for this prject
Using TestNg.xml file and the same is configured in pom.xml file.
Ran 'maven test' from eclispe and the test runs successfully based on the classes defined in testng.xml. no issues here
Tried the same from command prompt using mvn test from the project folder and it ran succesfully. no issues here too.
My requirement : Now i want to package this project either to executable jar or are there are any option to make a executable file so that i can schedule the run using a batch file.

To do this I ran the 'mvn package' command and it generated the jar file in the target folder. Now when i try to run this as java -jar myproj-0.0.1-SNAPSHOT.jar i get the message as "no main manifest attribute, in myproj-0.0.1-SNAPSHOT.jar". This is expected behavior since there is no main class in my case.
So i created a main class with just one line to print "text" and added the mainClass below entry in pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
    <archive>
    <manifest>
        <mainClass>mainPackage.MainOne</mainClass>
    </manifest>
</archive>
</configuration>
 </plugin> 
Then i ran mvn package and it generated the new jar. Then went to target folder of my project and ran the command as java -jar myProj.jar mainPackage.MainOne, it ran and just printed "text". MY TestNG tests did not run. It just ran main class :(.. What should i do?

Krishnan Mahadevan

unread,
Sep 12, 2014, 8:54:32 AM9/12/14
to testng...@googlegroups.com
In order for a jar to be considered as an executable jar, you would need to define a main method for sure.

If you want your main method to automatically start executing tests when you do a java -jar foo.jar then you would need to ditch the maven surefire plugin approach and instead resort to using the TestNG apis for running your tests.

You could create a main method that accepts a suite xml file as a parameter and then feeds that into the TestNG object to run your tests.




Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Nidhish Narayana

unread,
Sep 12, 2014, 12:52:15 PM9/12/14
to testng...@googlegroups.com

Yes.. you are right..thanks.. I made it to work.. :) for solution please check the below link.. I have added the answere there with the complete steps

http://stackoverflow.com/questions/25804102/executable-jar-for-selenium-testng-maven-project-which-dont-have-a-main-class

Regards,
Nidhish N

Reply all
Reply to author
Forward
0 new messages