【发布时间】:2017-12-20 15:02:03
【问题描述】:
我正在使用 Maven3 构建一个 Web 应用程序并通过 mvn jetty:run-war 运行它。现在我想在系统浏览器中从我的 maven 构建中打开网络应用程序。
【问题讨论】:
我正在使用 Maven3 构建一个 Web 应用程序并通过 mvn jetty:run-war 运行它。现在我想在系统浏览器中从我的 maven 构建中打开网络应用程序。
【问题讨论】:
我在 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>
【讨论】:
作为我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 欢迎。
【讨论】:
使用码头服务器。在 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>
现在构建使用
mvn clean install jetty:run
这将在端口 8080 启动 Jetty 服务器,您可以在执行 mvn 命令的机器上使用http://localhost:8080/shinchan URL 访问。
PS:
有关详细信息,请在此处阅读 Jetty wiki:http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
你可能想考虑jetty:deploy-war,但我认为这有点矫枉过正。
【讨论】:
./start-jetty.sh && firefox http://localhost:8080/shinchan 的东西 start jetty.sh 看起来像 mvn jetty:start & ; sleep 10 ;