Skip to content

Commit 13b42fe

Browse files
committed
U added winconfig.vmlocation property
1 parent d3733c8 commit 13b42fe

File tree

4 files changed

+94
-21
lines changed

4 files changed

+94
-21
lines changed

docs/windows-specific-properties.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<internalName>${name}</internalName>
2424
<originalFilename>${name}.exe</originalFilename>
2525

26+
<!-- choose EXE creation tool -->
27+
<exeCreationTool>launch4j|winrun4j</exeCreationTool>
28+
<vmLocation>relative/path/to/jvm.dll</vmLocation>
29+
2630
<!-- setup generation properties -->
2731
<setupMode>installForAllUsers|installForCurrentUser|askTheUser</setupMode>
2832
<setupLanguages>
@@ -67,27 +71,32 @@
6771
| `icoFile` | :x: | `null` | Icon file. If `null`, takes the default one. |
6872
| `generateSetup` | :x: | `true` | Generates Setup installer. |
6973
| `generateMsi` | :x: | `true` | Generates MSI installer. |
70-
| `generateMsm` | :x: | `false` | Generates MSI merge module. **Coming soon!** |
74+
| `generateMsm` | :x: | `false` | Generates MSI merge module. |
7175

7276
## Exe creation properties
7377

74-
| Property | Mandatory | Default value | Description |
75-
| ------------------- | --------- | --------------------- | -------------------------------------------- |
76-
| `headerType` | :x: | `"gui"` | EXE header type: `console` or `gui`. |
77-
| `wrapJar` | :x: | `true` | Wrap JAR file in native EXE. |
78-
| `companyName` | :x: | `${organizationName}` | EXE company name. |
79-
| `fileVersion` | :x: | `"1.0.0.0"` | EXE file version. |
80-
| `txtFileVersion` | :x: | `${version}` | EXE txt file version. |
81-
| `productVersion` | :x: | `"1.0.0.0"` | EXE product version. |
82-
| `txtProductVersion` | :x: | `${version}` | EXE txt product version. |
83-
| `fileDescription` | :x: | `${description}` | EXE file description. |
84-
| `copyright` | :x: | `${organizationName}` | EXE copyright. |
85-
| `productName` | :x: | `${name}` | EXE product name. |
86-
| `internalName` | :x: | `${name}` | EXE internal name. |
87-
| `originalFilename` | :x: | `${name}.exe` | EXE original filename. |
88-
| `trademark` | :x: | `null` | EXE trademark. |
89-
| `language` | :x: | `null` | EXE language. |
90-
| `exeCreationTool` | :x: | `launch4j` | EXE creation tool: `launch4j` or `winrun4j`. |
78+
| Property | Mandatory | Default value | Description |
79+
| ------------------- | --------- | --------------------- | ---------------------------------------------------------------------- |
80+
| `headerType` | :x: | `"gui"` | EXE header type: `console` or `gui`. |
81+
| `wrapJar` | :x: | `true` | Wrap JAR file in native EXE. |
82+
| `companyName` | :x: | `${organizationName}` | EXE company name. |
83+
| `fileVersion` | :x: | `"1.0.0.0"` | EXE file version. |
84+
| `txtFileVersion` | :x: | `${version}` | EXE txt file version. |
85+
| `productVersion` | :x: | `"1.0.0.0"` | EXE product version. |
86+
| `txtProductVersion` | :x: | `${version}` | EXE txt product version. |
87+
| `fileDescription` | :x: | `${description}` | EXE file description. |
88+
| `copyright` | :x: | `${organizationName}` | EXE copyright. |
89+
| `productName` | :x: | `${name}` | EXE product name. |
90+
| `internalName` | :x: | `${name}` | EXE internal name. |
91+
| `originalFilename` | :x: | `${name}.exe` | EXE original filename. |
92+
| `trademark` | :x: | | EXE trademark. |
93+
| `language` | :x: | | EXE language. |
94+
| `exeCreationTool` | :x: | `launch4j` | EXE creation tool: `launch    4j` or `winrun4j`. |
95+
| `vmLocation` | :x: | | `jvm.dll` path relative to the bundled JRE. **Only for WinRun4J**. \*1 |
96+
97+
> \*1: If a JRE is bundled and `vmLocation` is not specified, it uses `bin\client\jvm.dll` or `bin\server\jvm.dll` as VM location by default.
98+
99+
91100

92101
## Setup generation properties
93102

src/main/java/io/github/fvarrui/javapackager/model/WindowsConfig.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class WindowsConfig implements Serializable {
4747
private Registry registry = new Registry();
4848
private boolean removeOldLibs = false;
4949
private WindowsExeCreationTool exeCreationTool = WindowsExeCreationTool.launch4j;
50+
private String vmLocation;
5051

5152
public File getIcoFile() {
5253
return icoFile;
@@ -295,6 +296,14 @@ public WindowsExeCreationTool getExeCreationTool() {
295296
public void setExeCreationTool(WindowsExeCreationTool exeCreationTool) {
296297
this.exeCreationTool = exeCreationTool;
297298
}
299+
300+
public String getVmLocation() {
301+
return vmLocation;
302+
}
303+
304+
public void setVmLocation(String vmLocation) {
305+
this.vmLocation = vmLocation;
306+
}
298307

299308
@Override
300309
public String toString() {
@@ -309,7 +318,7 @@ public String toString() {
309318
+ ", generateSetup=" + generateSetup + ", generateMsi=" + generateMsi + ", generateMsm=" + generateMsm
310319
+ ", msiUpgradeCode=" + msiUpgradeCode + ", wrapJar=" + wrapJar + ", setupLanguages=" + setupLanguages
311320
+ ", setupMode=" + setupMode + ", signing=" + signing + ", registry=" + registry + ", removeOldLibs="
312-
+ removeOldLibs + ", exeCreationTool=" + exeCreationTool + "]";
321+
+ removeOldLibs + ", exeCreationTool=" + exeCreationTool + ", vmLocation=" + vmLocation + "]";
313322
}
314323

315324
/**

src/main/java/io/github/fvarrui/javapackager/packagers/CreateWindowsExeWinRun4j.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
import java.io.File;
44
import java.io.FileOutputStream;
5+
import java.nio.file.Path;
6+
import java.util.Arrays;
7+
import java.util.List;
8+
import java.util.Optional;
59
import java.util.Properties;
610

11+
import org.apache.commons.lang3.StringUtils;
12+
713
import io.github.fvarrui.javapackager.model.Platform;
814
import io.github.fvarrui.javapackager.utils.CommandUtils;
915
import io.github.fvarrui.javapackager.utils.FileUtils;
@@ -15,6 +21,11 @@
1521
* Creates Windows executable with WinRun4j
1622
*/
1723
public class CreateWindowsExeWinRun4j extends AbstractCreateWindowsExe {
24+
25+
private static final String [] JVM_DLL_PATHS = {
26+
"bin/client/jvm.dll",
27+
"bin/server/jvm.dll"
28+
};
1829

1930
public CreateWindowsExeWinRun4j() {
2031
super("winrun4j");
@@ -42,6 +53,9 @@ protected File doApply(WindowsPackager packager) throws Exception {
4253
File libsFolder = packager.getLibsFolder();
4354
File appFolder = packager.getAppFolder();
4455
String mainClass = packager.getMainClass();
56+
File jreDestinationFolder = packager.getJreDestinationFolder();
57+
boolean bundleJre = packager.getBundleJre();
58+
String vmLocation = packager.getWinConfig().getVmLocation();
4559

4660
createAssets(packager);
4761

@@ -58,7 +72,48 @@ protected File doApply(WindowsPackager packager) throws Exception {
5872
File rcedit = new File(getOutputFolder(), "rcedit.exe");
5973
FileUtils.copyResourceToFile("/windows/rcedit-x64.exe", rcedit);
6074

61-
// generates ini file
75+
// uses vmLocation only if a JRE is bundled
76+
if (bundleJre) {
77+
78+
// checks if vmLocation property is specified in winConfig
79+
if (!StringUtils.isBlank(vmLocation)) {
80+
81+
// checks if specified vmLocation exists
82+
if (!new File(jreDestinationFolder, vmLocation).exists()) {
83+
throw new Exception("VM location '" + vmLocation + "' does not exist");
84+
}
85+
86+
vmLocation = vmLocation.replaceAll("/", "\\\\");
87+
88+
} else {
89+
90+
// searchs for valid jvm.dll file in JRE
91+
Optional<File> jvmDllFile = Arrays.asList(JVM_DLL_PATHS)
92+
.stream()
93+
.map(path -> new File(jreDestinationFolder, path))
94+
.filter(file -> file.exists())
95+
.findFirst();
96+
97+
// checks if found jvm.dll
98+
if (!jvmDllFile.isPresent()) {
99+
throw new Exception("jvm.dll not found!");
100+
}
101+
102+
// relativize jvm.dll path to JRE, in order to use it a "vm.location"
103+
Path jreDestinationPath = jreDestinationFolder.toPath();
104+
Path jvmDllPath = jvmDllFile.get().toPath();
105+
vmLocation = jreDestinationPath.relativize(jvmDllPath).toString();
106+
107+
}
108+
109+
// sets vmLocation in winConfig, so it will be used when rendering INI file
110+
packager.getWinConfig().setVmLocation(vmLocation);
111+
112+
Logger.info("Using 'vmLocation=" + vmLocation + "'!");
113+
114+
}
115+
116+
// generates ini file
62117
File genericIni = new File(getOutputFolder(), "app.ini");
63118
VelocityUtils.render("windows/ini.vtl", genericIni, packager);
64119
Logger.info("INI file generated in " + genericIni.getAbsolutePath() + "!");

src/main/resources/windows/ini.vtl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ classpath.${classpathCounter}=$!{cp}
88
#set ($classpathCounter=$classpathCounter+1)
99
#end
1010
#if ($info.bundleJre)
11-
vm.location=${info.jreDirectoryName}\bin\client\jvm.dll
11+
vm.location=${info.jreDirectoryName}\\${info.winConfig.vmLocation}
1212
#end
1313
#if (!$info.bundleJre && $info.jreMinVersion)
1414
vm.version.min=${info.jreMinVersion}

0 commit comments

Comments
 (0)