简体   繁体   English

Spring Boot 强制无头模式

[英]Spring boot forcing headless mode

I am trying to build a simple maven based app for automated testing using SikuliX.我正在尝试使用 SikuliX 构建一个简单的基于 maven 的应用程序进行自动化测试。 The app is currently created as a most recent spring-boot application (v. 1.4.1).该应用程序当前创建为最新的 spring-boot 应用程序 (v. 1.4.1)。 The app itself is rather simple (POC at the moment), one class as an Application (SpringBootApplication annotated, implementing CommandLineRunner) and one service (autowired, impl and interface).应用程序本身相当简单(目前是 POC),一个类作为应用程序(SpringBootApplication 注释,实现 CommandLineRunner)和一个服务(自动装配、实现和接口)。 Nothing more, no other dependencies (just SikuliX, commons-lang3 and spring-boot-starter).仅此而已,没有其他依赖项(只有 SikuliX、commons-lang3 和 spring-boot-starter)。

However, when I do run the app, Sikuli subsystem complaints about being run in headless mode.但是,当我运行该应用程序时,Sikuli 子系统抱怨以无头模式运行。

I have tried using SpringApplicationBuilder.headless(false).web(false).run(args);我试过使用SpringApplicationBuilder.headless(false).web(false).run(args); setting System.setProperty("java.awt.headless", "false");设置System.setProperty("java.awt.headless", "false"); passing arguments to the JVM to disable headless mode.将参数传递给 JVM 以禁用无头模式。 None of the options alone works as well as their combination.单独的选项都不能像它们的组合一样有效。 Spring-boot always assumes headless mode. Spring-boot 始终采用无头模式。

Is there anybody who come across issue like this?有没有人遇到过这样的问题?

PS: os is mac and windows, java 1.8 PS:os是mac和windows,java 1.8

Have a nice day folks.祝大家有美好的一天。

J. J。

Sikuli cannot be run in a headless mode. Sikuli 不能在无头模式下运行。 This is a known limitation.这是一个已知的限制。 The reason for that is the Java Robot library that is being used internally by Sikuli.原因是 Sikuli 内部使用的 Java Robot 库。 In other words, you must have a running machine with a screen to make Sikuli work.换句话说,你必须有一台带屏幕的跑步机才能让斯库里工作。

I was having the same issue and fixed it by setting the java.awt.headless system property to false.我遇到了同样的问题,并通过将 java.awt.headless 系统属性设置为 false 来修复它。 This is the suggestion from M. Deinum in a comment to the OP so credit to them.这是 M. Deinum 在对 OP 的评论中提出的建议,因此要归功于他们。

Here is how I added it to my main application file:这是我将它添加到我的主应用程序文件的方法:

public static void main(String[] args) {
    System.setProperty("java.awt.headless", "false"); //ADD THIS
    SpringApplication.run(MyClass.class, args);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM