基本上,我想将以下逻辑放入 install4j 文件中。它将用于在应用程序中设置 vmoptions。该逻辑似乎在测试类中运行良好,但是在 install4j 文件中以正确的格式将其放置在正确的位置对我来说相当麻烦。我只需要将语言环境拆分为三个单独的 vmoptions:
-Duser.language="en"
-Duser.country="US"
-Duser.variant=""
如果未提供国家/地区或变体,我只想为其值放置一个空白字符串。
如果需要任何其他信息或代码来帮助我们完成此场景,请告诉我,如果可用,我会提供。
用户选择的语言环境被放入${installer:sys.languageId}
. 我尝试通过使用获取该变量中的字符串及其长度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);
}
}
}
这是上面代码的输出。