Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a browser with a url from maven build

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.

like image 229
Michael K. Avatar asked Oct 04 '12 11:10

Michael K.


People also ask

How do you generate a site for a project with Maven?

To generate a site, just run mvn site:site or mvn site. To view the generated site on a local machine, run mvn site:run. This command will deploy the site to a Jetty web server at the address localhost:8080.

What does mvn site do?

So, a "mvn clean site" actually performs the pre-clean and clean phases of the clean lifecycle and then performs the pre-site and site phases of the site lifecycle.


2 Answers

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>
like image 102
Michael K. Avatar answered Oct 27 '22 01:10

Michael K.


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.

like image 20
Jaroslav Tulach Avatar answered Oct 26 '22 23:10

Jaroslav Tulach