title: How to Create a Compatible JAR File for Selenium Tests?
body: <p>I have created a script to perform few automated tests in Selenium for a website using Java in Eclipse.</p>
  
  <p>My aim here is to create a JAR file for my automated tests so that when the file is simply executed, the tests will run on any other system configured with a Selenium environment. For that I have created a runnable JAR file from Eclipse by clicking on the Export option from the File menu. The name of the JAR file is <code>Test MyWebsite.jar</code>.</p>
  
  <p>The source code of my Java classes is given below:</p>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>package testproject.main;
  
  import testproject.testmywebsite.*;
  
  
  public class Main {
  
      public static void main(String[] args) {
          TestMyWebsite tmw = new TestMyWebsite();
          tmw.testMyWebsite();
          tmw.stopTest();
      }
  }
  </code></pre>
  
  <p><strong>TestMyWebsite.java</strong></p>
  
  <pre><code>import org.openqa.selenium.*;
  import org.openqa.selenium.chrome.ChromeDriver;
  import java.io.*;
  import testproject.testmywebsite.tools.*;
  import testproject.testmywebsite.login.*;
  
  public class TestMyWebsite {
  
      private WebDriver driver;
  
      public TestMyWebsite() {
          setUp();
      }
  
      private void setUp() {
          // Create a new instance of the Chrome driver
          driver = new ChromeDriver();
          driver.manage().window().maximize();
      }
  
      public void testMyWebsite() {
          testLogin();
      }
  
      public void testLogin() {
          TestLogin tl = new TestLogin(driver);
          tl.testLogin();
      }
  
      public void stopTest() {
          //Close the browser
          driver.quit();
      }
  }
  </code></pre>
  
  <p><strong>TestLogin.java</strong></p>
  
  <pre><code>import org.openqa.selenium.*;
  import org.openqa.selenium.chrome.ChromeDriver;
  
  public class TestLogin {
  
      private WebDriver;
  
      public TestLogin(WebDriver driver) {
          this.driver = driver;
      }
  
      public void testLogin() {
          //Perform the login test
      }
  }
  </code></pre>
  
  <p>The problem here is that despite setting up and configuring the environment on other computers with the Selenium webdriver, copying the <code>Test MyWebsite.jar</code> in the third-party computer and running the file by double-clicking it, the tests do not run successfully. What happens is the Chrome browser opens momentarily and then closes without opening the 'MyWebsite's' URL. In other words, only the two lines of code in the <code>Main.java</code> class are executed. The JAR file is unable to find the other two associated classes in the Eclipse project. However when I execute the file in my computer the tests are perfectly run, which means that there is a problem with how I have created the JAR file. Please note that these are just three classes of the 12 classes I have created in 5 different packages in my Eclipse project to make understanding easier.</p>
  
  <p>Can anyone please tell me where am I going wrong in creating my JAR file which will run both on my computer as well as on another computer configured with the Selenium environment? As a beginner in Selenium I had followed <a href="http://www.softwaretestingclub.com/profiles/blogs/selenium-2-0-webdriver-how-to-configure-selenium-webdriver-in" rel="nofollow">these</a> instructions while creating my Selenium project in Eclipse. Replies at the earliest will be highly appreciated.</p>
  
  <p>Thank you.</p>