0

i read lots of questions, tutorials but it is not working & there is nothing for beginners. i have created a simple project in maven selenium & it opens https://www.google.com, i want to Run this using Jar file instead of alway running this in Eclipse. to creating JAR i have tried Eclipse Export method but it shows errors such as "Main class not found" . so JAR did not worked. then i heard to use something "maven-assembly-plugin" for creating runnable JAR, but i did not found step by step guide anywhere for beginners. here is my code of my main project file

package com.org.learningMaven;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class HelloWorldTest {

@Test
public void login() {
    System.out.println("Opening Google!");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.google.com/");
}

}

2nd method i tried, i added this in pom.xml

     <build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
       <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
          <manifest>
        <mainClass>HelloWorldTest</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>

then right click on project run as>5 maven build... and i write "clean compile assembly:single" in Goal then clicked apply & Run. and i found a new jar file in "Target" directory of project, by nothing happened when clicked that JAR. can someone plz tell me easy steps for Runnable JAR file of Maven? Thanks

carol
  • 311
  • 2
  • 4
  • 14
  • HelloWorldTest is not a main class. A main class is a class that has a `static void main(String[] args)` method. That java can execute. What you have there is a JUnit test, that a JUnit test runner can execute. – JB Nizet Dec 25 '15 at 00:41
  • so can i made executable JAR file of this JUnit test ? – carol Dec 25 '15 at 00:43
  • No. An executable jar file must have a main class. And a JUnit test is not a main class. – JB Nizet Dec 25 '15 at 00:47
  • and there is no way to make "Main Class" in this JUnit test, to make its JAR ? – carol Dec 25 '15 at 00:48
  • Why do you want to put these 3 lines into a JUnit test? It's not a test. It doesn't make any assertion, but just uses Selenium. Make it a main class. – JB Nizet Dec 25 '15 at 00:56
  • i just want to learn this so i made this code very simpler. it show error when i try to make this login() a main class – carol Dec 25 '15 at 01:05
  • And the code is? And the error is? – JB Nizet Dec 25 '15 at 01:06
  • Please replace `public void login()` with `static void main(String[] args)` as implied above and remove the `@Test` annotation. You can also use the `maven-dependency-plugin` instead as described here: http://stackoverflow.com/a/4323501/1990536 – Rai Dec 25 '15 at 02:52

0 Answers0