Question

Basically, I want to put the below logic into an install4j file. It will be used to set the vmoptions in an application. The logic seems to work fine in a test class, but getting it in the correct place and in the correct format within the install4j file has proven rather troublesome for me. I just need to split up the locale into three separate vmoptions:

-Duser.language="en"
-Duser.country="US"
-Duser.variant=""

If country or variant aren't provided, I simply want to put a blank string for it's value.
If any additional information or code is needed to help us work through this scenario, let me know and I will provide it if it is available.

The user selected locale is put into ${installer:sys.languageId}. I try to get the string in that variable and it's length by using getVariable(languageId).length()

public class VmOptionsTest {

    public static void main(String[] args) {

        //languageOne represents ${installer:sys.languageId} in this test case
        String languageOne = "en_US";
        String language = "";
        String country = "";
        String variant = "";

        //for all the if and else if statements
        //this is where I would put getVariable(languageId).length() in install4j file
        if (languageOne.length() == 2) {

            language = languageOne;
            country = "";
            variant = "";

            JOptionPane.showMessageDialog(null, "-Duser.language=" + language + "\n" +
                    "-Duser.country=" + country + "\n" + "-Duser.variant=" + variant);
        } else if (languageOne.length() == 5) {

            language = languageOne.substring(0, 2);
            country = languageOne.substring(3, 5);
            variant = "";

            JOptionPane.showMessageDialog(null, "-Duser.language=" + language + "\n" +
                    "-Duser.country=" + country + "\n" + "-Duser.variant=" + variant);
        } else if (languageOne.length() > 5) {

            language = languageOne.substring(0, 2);
            country = languageOne.substring(3, 5);
            variant = languageOne.substring(6, 8);

            JOptionPane.showMessageDialog(null, "-Duser.language=" + language + "\n" +
                    "-Duser.country=" + country + "\n" + "-Duser.variant=" + variant);
        }


    }
}

This is the output of the above code.

enter image description here

Was it helpful?

Solution

Well, I finally figured it out.

In my install4j IDE, I created 3 new installer variables.

${installer:language} 
${installer:country} 
${installer:variant}

Then I wrote a script for each one.


**${installer:language}**

String language = context.getVariable("language").toString();
String languageId = context.getVariable("sys.languageId").toString();

if(languageId.length() >= 2){

  language = languageId.substring(0,2);
}

return language;

**${installer:country}**

String country = context.getVariable("country").toString();
String languageId = context.getVariable("sys.languageId").toString();

if(languageId.length() == 2){

  country = " ";

}else if(languageId.length() > 2){

  country = languageId.substring(3, 5);

}

return country;

**${installer:variant}**

String variant = context.getVariable("variant").toString();
String languageId = context.getVariable("sys.languageId").toString();

if(languageId.length() < 8){

  variant = " ";

}else{       
    variant = languageId.substring(6, 8);         
}

return variant;

Finally, I set the VMoptions

-Duser.language=${installer:language}
-Duser.country=${installer:country}
-Duser.variant=${installer:variant}

Hope this helps if anyone runs across a similar issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top