start jetty-maven-plugin than execute exec-maven-p

2019-09-02 15:50发布

问题:

Could anyone help me with this!!

My pom.xml

    "start the jetty server
<plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.14.v20131031</version>
                <executions>
                    <execution>
                        <phase>
                                test
                        </phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>

                </executions>
                <configuration>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                            <port>3663</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>

" run the jasmine unit tests on the jetty server

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>PhantomJS Unit Testing</id>
                        <phase>test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>

                    <executable>${basedir}/src/main/webapp/test/phantomjs_framework/phantomjs.exe</executable>

                    <workingDirectory>${basedir}/src/main/webapp/test/phantomjs_framework</workingDirectory>

                    <arguments>
                        <!-- <argument>run_jasmine.js</argument> -->
                        <argument>phantomjs_jasminexml_runner.js</argument>
                        <argument>http://localhost:3663/test/phantomjs_framework/test_runner.html</argument>
                        <argument>${project.build.directory}/surefire-reports</argument>
                    </arguments>
                </configuration>
            </plugin>

The idea is to launch the jetty server using jetty-maven-plugin than execute the jasmine tests using exec-maven-plugin.

Currently i have to do the following:

  1. run "jetty:run" to start the jetty server
  2. run "mvn test" to run the tests

it works fine!!

BUT:

Well, i'm hoping to be able to only run "mvn test" and the jetty server will automatically start, currently it does not happen and the tests fails i have to run "jetty:run" manually first

I went back and forth and couldn't get it to work

Any help please!! Thank you. Kais.

回答1:

From what I can tell you're not using this is an integration test, so invoke the jetty-maven-plugin in the test-compile phase instead.

Alternatively, set this up in the pre-integration-test phase, as suggested by Karl-Heinz and then have your tests executed with the failsafe-maven-plugin in the integration-test phase.