【问题标题】:How to open a browser with a url from maven build如何使用来自 maven build 的 url 打开浏览器
【发布时间】:2017-12-20 15:02:03
【问题描述】:

我正在使用 Maven3 构建一个 Web 应用程序并通过 mvn jetty:run-war 运行它。现在我想在系统浏览器中从我的 maven 构建中打开网络应用程序。

【问题讨论】:

    标签: maven-2 maven-3


    【解决方案1】:

    我在 os windows 上解决了我的问题,这是我目前唯一的构建系统。在码头服务器启动并托管我的网络应用程序后,构建通过 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>
    

    【讨论】:

    • jetty:run 之后如何运行它? antrun:run 在我的情况下没有启动浏览器
    【解决方案2】:

    作为我bck2brwsr VM 工作的一部分,我编写了一个可以在每个平台/JDK 上打开浏览器的 Maven 插件。它可用于显示项目中的任何静态页面。以下示例打开浏览器,内容为pom.xml 文件:

    <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>
    

    我知道打开静态页面并不完美,但它可以包含适当的重定向,对吧?此外,如果有兴趣,可以轻松改进插件以打开任何 URL。 Pull Requests 欢迎。

    【讨论】:

      【解决方案3】:
      1. 使用码头服务器。在 build 标签下的 pom.xml 中添加 Jetty 插件,如下所示:

         <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. 现在构建使用

          mvn clean install jetty:run
        
      3. 这将在端口 8080 启动 Jetty 服务器,您可以在执行 mvn 命令的机器上使用http://localhost:8080/shinchan URL 访问。

      PS:
      有关详细信息,请在此处阅读 Jetty wiki:http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
      你可能想考虑jetty:deploy-war,但我认为这有点矫枉过正。

      【讨论】:

      • 你误会了我。码头服务器的使用不是我的问题。我的问题是在码头服务器启动后使用我的网络应用程序的 URL 打开操作系统上的浏览器。
      • 我还是没找到你。您希望构建也启动本地浏览器吗?它会自动将 webapp 的 URL 加载到其中。
      • 我担心Maven系统中没有内置任何东西,因为它会非常操作系统到操作系统,并且取决于您拥有的浏览器。您可以在后台运行 mvn 并启动您的浏览器。类似 ./start-jetty.sh &amp;&amp; firefox http://localhost:8080/shinchan 的东西 start jetty.sh 看起来像 mvn jetty:start &amp; ; sleep 10 ;
      • 最好的建议是使用 selenium 来做这些事情。 Selenium 可以启动您的浏览器,您可以运行您的测试。最好的办法是为此目的使用集成测试。
      猜你喜欢
      • 2020-05-27
      • 2013-03-10
      • 2021-07-12
      • 2014-12-06
      • 2014-02-10
      • 2019-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多