Gradle 为 javafx 应用程序构建:虚拟键盘由于缺少系统而无法工作 属性

Gradle build for javafx application: Virtual Keyboard is not working due to missing System property

我正在使用 javafx 应用程序,我们为此应用程序开发了一个 gradle 构建系统。可以使用以下 gradle 任务创建 jar 文件:

    task fatJar(type: Jar) {
manifest {
    attributes 'Main-Class': 'myProject'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA' 
with jar

}

目前为止一切正常 - 唯一的问题是我们要使用虚拟键盘 (javafx),因此我们需要设置以下系统属性:

     systemProperty 'com.sun.javafx.isEmbedded', 'true' 
     systemProperty 'com.sun.javafx.touch', 'true'       
     systemProperty 'com.sun.javafx.virtualKeyboard', 'javafx' 

我可以在 gradle 构建中设置此属性吗,或者是否需要使用

启动应用程序

java -Dcom.sun.javafx.isEmbedded=true -Dcom.sun.javafx.touch=true -Dcom.sun.javafx.virtualKeyboard=javafx -jar myProject.jar

此致

__________________________________-

解决方案(非常感谢 Frederic Henri :-))是写一个包装器 class 就像

public class AppWrapper 
{   
    public static void main(String[] args) throws Exception 
    {  
        Class<?> app = Class.forName("myProject");         
        Method main = app.getDeclaredMethod("main", String[].class);     
        System.setProperty("com.sun.javafx.isEmbedded", "true"); 
        System.setProperty("com.sun.javafx.touch", "true");          
        System.setProperty("com.sun.javafx.virtualKeyboard", "javafx");     
        Object[] arguments = new Object[]{args};
        main.invoke(null, arguments);
    }
}

我不认为这项工作可以从构建阶段完成(我很乐意犯错并看到另一个答案)-

这里似乎还有另一个答案Java: Modify System properties via runtime,它说要围绕你的最终 main 方法编写一个包装器,这样你就可以传递你需要的属性,但不确定它有多好。