6

I'm building a web-application with Maven3 and run it via mvn jetty:run-war. Now I'd like to open the web-app from my maven build in the system browser.

3 Answers 3

4

I solved my problem on os windows, which is currently my only build system. After the jetty server is started and hosting my web-app the build makes a start call via antrun:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
      <execution>
        <id>Run URL in system browser.</id>
        <phase>install</phase>
        <configuration>
          <target>
            <exec executable="start" vmlauncher="false">
              <arg line="http://localhost:8080/rap?startup=entrypoint"/>
            </exec>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
Sign up to request clarification or add additional context in comments.

1 Comment

how to run that after jetty:run? antrun:run is not starting the browser in my case
1

I have written a Maven plugin that can open browser on each platform/JDK as part of my bck2brwsr VM work. It can be used to show any static page in your project. Following example opens browser with content of pom.xml file:

<plugin>
    <groupId>org.apidesign.bck2brwsr</groupId>
    <artifactId>bck2brwsr-maven-plugin</artifactId>
    <version>0.22</version>
    <executions>
        <execution>
            <id>show-a-file</id>
            <phase>verify</phase>
            <goals>
                <goal>show</goal>
            </goals>
            <configuration>
                <directory>${basedir}</directory>
                <startpage>pom.xml</startpage>
            </configuration>
        </execution>
    </executions>
</plugin>

I know opening a static page isn't perfect, but it can contain appropriate redirect, right? Moreover, if there is an interested, the plugin can easily be improved to open any URL. Pull Requests welcomed.

Comments

-1
  1. Use Jetty server. Add Jetty plugin in your pom.xml under build tag like this:

     <plugins>
        <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
            <webApp>
              <contextPath>/shinchan</contextPath>
            </webApp>
          </configuration>
        </plugin>
    <!-- more plugin tags if any -->
    <plugins>
    
  2. now build using

      mvn clean install jetty:run
    
  3. this will start Jetty server at port 8080, and you can access using http://localhost:8080/shinchan URL on the machine the mvn command is executed.

PS:
For more details read Jetty wiki here: http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
you may want to consider jetty:deploy-war, but I think it's an overkill.

4 Comments

You've missunderstood me. The using of the jetty server is not my problem. My problem is to open the browser on the operation system with the URL to my web-app after the the jetty server is started.
I still did not get you. You want the build to launch your local browser too? And it automatically loads the webapp's URL into it.
I afraid that there exists no thing build-into Maven system, because it will very OS to OS, and depends on what browser you have. You may run mvn in background and launch your browser. some thing of this sort ./start-jetty.sh && firefox http://localhost:8080/shinchan where start jetty.sh looks something like mvn jetty:start & ; sleep 10 ;
Best suggestions is to use selenium to do such things. Selenium can start your browser and you can run your tests. Best thing is to use integration tests for such purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.