1

Below is the relevant part of my POM -

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
        <execution>
            <id>StartHub</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-jar</argument>
                    <argument>${basedir}/src/lib/Hub/selenium-server-standalone-2.53.0.jar</argument>
                    <argument>-role</argument>
                    <argument>hub</argument>
                    <argument>-throwOnCapabilityNotPresent</argument>
                    <argument>false</argument>
                    <argument>-newSessionWaitTimeout</argument>
                    <argument>20000</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>StartNode</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-jar</argument>
                    <argument>${basedir}/src/lib/Node/selenium-server-standalone-2.53.0.jar</argument>
                    <argument>-hub</argument>
                    <argument>http://127.0.0.1:4444/register/grid</argument>
                    <argument>-port</argument>
                    <argument>5555</argument>
                    <argument>
                        Dwebdriver.chrome.driver=${basedir}/chromedriver.exe</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

I was trying to use the exec plugin to execute a jar(selenium standalone server) in two configurations(hub and Node).

My issue is that the jar is executed only once in the configuration specified between the first pair of "execution" tags. I have searched extensively for a solution and the only thing I found was that the id's for different executions need to be different, which I rectified. I still can't seem to manage to run the jars twice even though I can run any one of them successfully if I comment out the execution of the other.

I should also mention that I'm running the project in Eclipse, so ideally what I would want to do is right-click on the POM.xml click on Run-as and select "Maven test".

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Savvy
  • 547
  • 5
  • 12

1 Answers1

1

This is not a Maven executions issue but rather an issue related to what you are executing: a blocking process (the first server) which would stop the build listening for a node which would never get connected (because its execution won't start).

Changing your pom to the following:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.5.0</version>
    <executions>
        <execution>
            <id>StartHub</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-version</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>StartNode</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-version</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

It would perfectly execute the two exec executions, printing twice the Java version. Note: the snippet is a copy and paste from your question, just replacing arguments of the java command to its version option.


What you are most probably looking for is to execute the two commands in background or at least in a non-blocking way in order to get the second executed, then proceed with the build (to execute some tests I presume).

Check this SO question on how to achieve it: instead of using the exec-maven-plugin, use the maven-antrun-plugin to launch the two selenium commands.


As a further note, you should probably consider using the maven-failsafe-plugin instead and execute integration tests, attaching the executions above to the pre-integration-test phase and stop them during the post-integration-test phase in order to properly clean them.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • Thanks a lot for the answer. I have handled this using process builder, but its nice to know why it wasn't working and about the Antrun plugin. I am aware of the failsafe plugin, but I didn't go for it because there is nothing I need to do before and after the tests that I can't handle using the annotations provided by testNG. I would be interested in knowing if handling such tasks via Maven has any inherent advantage over doing it programmatically. But I guess that is a different question altogether!! Once again thanks for your time!! I'm accepting this as the answer – Savvy May 26 '16 at 13:52