title: Better way to add PhantomJS binary to a maven project?
body: <p>I tried using the phantomjs-maven-plugin to install phantomjs binary. I wanted to run my tests on a Tomcat7 server that is why I need to configure binary automatically.</p>
  
  <p>Here is my pom.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;properties&gt;
      &lt;ghostdriver.version&gt;1.2.0&lt;/ghostdriver.version&gt;
      &lt;phantomjs.version&gt;1.9.7&lt;/phantomjs.version&gt;
      &lt;phantomjs-maven-plugin.version&gt;0.7&lt;/phantomjs-maven-plugin.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
          &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
          &lt;version&gt;2.47.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.github.detro&lt;/groupId&gt;
          &lt;artifactId&gt;phantomjsdriver&lt;/artifactId&gt;
          &lt;version&gt;${ghostdriver.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
          &lt;!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" --&gt;
          &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
          &lt;version&gt;2.21&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
          &lt;version&gt;2.21&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-media-json-jackson&lt;/artifactId&gt;
          &lt;version&gt;2.21&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
  
      &lt;plugins&gt;
  
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.3&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.6&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
                  &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;groupId&gt;com.github.klieber&lt;/groupId&gt;
              &lt;artifactId&gt;phantomjs-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;${phantomjs-maven-plugin.version}&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;install&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;version&gt;1.9.7&lt;/version&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.17&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;systemPropertyVariables&gt;
                      &lt;phantomjs.binary&gt;${phantomjs.binary}&lt;/phantomjs.binary&gt;
                  &lt;/systemPropertyVariables&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
      &lt;/plugins&gt;
  
  &lt;/build&gt;
  </code></pre>
  
  <p>And then here is how I am initializing the webdriver ....just look the constructor and skip to the main() function in bottom </p>
  
  <pre class="lang-java prettyprint-override"><code>public class FindTrains {
  
      private WebDriver driver;
      //private WebDriverWait wait;
      JavascriptExecutor js;
  
      String baseURL = "http://www.indianrail.gov.in/inet_Srcdest.html";
  
      public FindTrains(){
  
          driver = new PhantomJSDriver();
          //((HtmlUnitDriver)driver).setJavascriptEnabled(true);
          //wait = new WebDriverWait(driver, 2);
          js = (JavascriptExecutor) driver;
      }
  
      public void getTrains(String src, String dest){
          driver.get(baseURL);    
  
          WebElement elemSrc =  driver.findElement(By.xpath(xpathSrc));
          setAttributeValue(elemSrc, src.toUpperCase());
  
          WebElement elemDest = driver.findElement(By.xpath(xpathDest));
          setAttributeValue(elemDest, dest.toUpperCase());        
  
          WebElement elemGetDetails = driver.findElement(By.xpath("//*[@id='formId']/table/tbody/tr/td/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr[16]/td[2]/input[1]"));
          elemGetDetails.click();
  
          System.out.println(driver.getCurrentUrl()+ " "+ driver.getTitle());
  
      }
  
      public void setAttributeValue(WebElement elem, String value){
          String scriptSetAttrValue = "arguments[0].setAttribute(arguments[1],arguments[2]);";        
          js.executeScript(scriptSetAttrValue, elem, "value", value);
      }
      public static void main(String [] args){
          System.out.println(System.getProperty("phantomjs.binary"));
          new FindTrains().getTrains("nad", "ndls");
  
      }
  } 
  </code></pre>
  
  <p>So the problem is that the I am unable to verify that my whether the binary has been installed or not ....and even if it did, then why does <code>main() prints null for system.property("phantomjs.binary")</code></p>
  
  <p>I provided my complete pom.xml and java code... please help me see what I am 
  doing wrong</p>
  
  <p>Edit:</p>
  
  <p>In the main() function I invoke <code>FindTrains</code> by creating an object of <code>FindTrains</code> and calling <code>getTrains()</code> on that object. but since the <code>driver</code> is  not configured because of missing binary ....the first line of <code>main()</code> prints <code>null</code>.</p>