0

i am using a javafx application and we developed a gradle build system for this application. The jar file can be created with the following gradle task:

    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

}

This works so far - the only problem is that we want to use the virtual keyboard (javafx) and therefore we need to set the following system properties:

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

Can i set this properties in the gradle build or is it necessary to start the application with

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

best regards

__________________________________-

The solution (big thanks to Frederic Henri :-)) is to write a wrapper class like

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);
    }
}
bernhard
  • 3
  • 3
  • if you need those variables to run your program (not gradle) you would need to pass when you run as you indicated or set those variables directly in your project (somewhere in your main method) – Frederic Henri Sep 03 '15 at 11:01
  • I have already tried to set the variables in the main method like System.setProperty("com.sun.javafx.isEmbedded", "true"); System.setProperty("com.sun.javafx.touch", "true"); System.setProperty("com.sun.javafx.virtualKeyboard", "javafx"); but this is somehow ignored ... – bernhard Sep 03 '15 at 11:14
  • check http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java or http://www.coderanch.com/t/584969/java/java/set-environment-variable – Frederic Henri Sep 03 '15 at 11:43
  • but an environment variable is not the same as a system property - or is it the same? – bernhard Sep 06 '15 at 17:37
  • and the function System.setProperty() seems to work - with the function System.getProperty() i get the correct values during program execution ... I think the only problem is that the variables are set too late during execution .... – bernhard Sep 06 '15 at 17:39
  • sorry yes you're right I got confused b/w the 2 and mixed up your questions – Frederic Henri Sep 06 '15 at 19:03

1 Answers1

0

I dont think this job can be done from the build phase (I'd be happy to be wrong and see another answer though) -

It seems there is another answer here Java: Modify System properties via runtime where it says to write a wrapper around your final main method and so you can pass the properties you need, not sure how good it is though.

Community
  • 1
  • 1
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • hey cool - it seems to work!! After adjusting the wrapper the virtual keyboard pops up in the jar build :-) Thanks !!! – bernhard Sep 06 '15 at 21:08