我在 Linux 上使用 Maven 3.0.3、GWT 2.4。我想在运行一些测试时设置 GWT 无头模式(例如设置 -Djava.awt.headless=true)。我的问题是,在通过 Maven 运行 GWT 测试时如何设置该参数?我通过运行运行我的 GWT 测试
mvn clean test
谢谢, - 戴夫
您可以通过 surefire 插件传递配置参数。喜欢:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<systemPropertyVariables>
<java.awt.headless>true</java.awt.headless>
</systemPropertyVariables>
</configuration>
</plugin>
...
参考:http ://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html
此答案的旧版本使用现在已弃用的“systemProperties”,您需要将其用于较旧的surefire版本:
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<systemProperties>
<java.awt.headless>true</java.awt.headless>
</systemProperties>
</configuration>
</plugin>
...
有关更多配置选项,请查看 Surefire 手册页: http ://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
如果我猜对了,当应用程序无法显示 GUI 时,您正在以无人值守模式(可能是 Hudson 或 CruiseControl)在服务器上运行测试。
还有另一种方法可以解决您的问题(假设您的目标是运行测试)。我使用 Xvfb - 一个 X Windows 系统虚拟帧缓冲 X 服务器(一种虚拟屏幕)。更简单的方法是在需要时为应用程序提供屏幕,而不是学习如何强制它在无头模式下工作。(特别是在我管理大约 100 个 Maven 项目的情况下)
你可以做什么:
确保您在运行测试的 PC/服务器上安装了 X 窗口系统。如果您需要提示如何为您的 linux 安装执行此操作,只需使用“安装 x 窗口”点击 Google。
安装 Xvfb
sudo apt-get install Xvfb(对于 Ubuntu Linux)或
百胜搜索 Xvfb(对于 CentOS,要获得确切的软件包名称,然后 yum install ...)或任何适合您的 lunux 发行版
创建包含“localhost”和“servername.yourcompany.com”的 2 行的 xvfb.hosts 文件。将其存放在某个地方。
nohup Xvfb :99 -auth xvfb.hosts > xvfb.log &
(或将此命令设置为在服务器启动时运行)
不要忘记为运行测试的会话提供环境变量:
出口显示=:99
我不能说具体怎么做,因为我不知道你的计算配置。我在 CruiseControl 启动脚本和 Hudson 安装中设置了 DISPLAY。
这对我来说很好,我不必关心我公司所有项目的任何类型的自动 GUI 测试。希望这会对你有所帮助。