From 7fde0e0f89c78a8081509d6f93b95766cd7dc6aa Mon Sep 17 00:00:00 2001 From: Geertjan Wielenga Date: Thu, 1 Oct 2026 14:58:32 +0200 Subject: [PATCH] Set bundled JDK home in netbeans.conf via ${BASEDIR} (#133) The Windows installer set the bundled JDK via --jdkhome on the Start Menu shortcut, so launching the executable directly - eg. via "Open With..." on a file - did not find the bundled JDK and either fell back to a system JDK or failed to launch. Write the bundled JDK location into netbeans.conf relative to the installation using the launcher's ${BASEDIR} token (now supported by the IDE and platform launchers), setting both jdkhome and netbeans_jdkhome. This resolves however the application is launched. The shortcut --jdkhome parameter is kept so packaging of older launchers that lack ${BASEDIR} support is unaffected. This applies to all packagers that bundle the runtime inside the application directory; the previous plain relative path was replaced. --- README.md | 5 +++-- .../netbeans/nbpackage/AbstractPackagerTask.java | 13 ++++++++++--- .../org/apache/netbeans/nbpackage/TestUtils.java | 4 +++- .../nbpackage/innosetup/InnoSetupPackagerTest.java | 5 +++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3c86353..bb7a6a5 100644 --- a/README.md +++ b/README.md @@ -97,8 +97,9 @@ wine C:\\Program\ Files\ \(x86\)\\Inno\ Setup\ 6\\ISCC.exe $1 ### `--type zip` Mainly for debugging purposes, although can be used to bundle an RCP application -with local runtime. As the IDE launcher does not yet support relative JDK location, -this is less useful there. +with local runtime. When a runtime is bundled, the JDK location is written into +`netbeans.conf` relative to the installation using the launcher's `${BASEDIR}` +token, so it is found however the application is launched. ## Building from source diff --git a/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java b/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java index d8e65c1..d94cd81 100644 --- a/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java +++ b/src/main/java/org/apache/netbeans/nbpackage/AbstractPackagerTask.java @@ -360,9 +360,16 @@ private void copyRuntimeFromDirectory(Path runtime, Path destDir) throws IOExcep private void addRuntimeToConf(Path conf, String jdkhome) throws IOException { var contents = Files.readString(conf); - contents = contents.replace("#jdkhome=\"/path/to/jdk\"", "jdkhome=\"" + jdkhome + "\""); - // @TODO - fix this when relative links work with IDE launcher - // contents = contents.replace("#netbeans_jdkhome=\"/path/to/jdk\"", "netbeans_jdkhome=\"" + jdkhome + "\""); + // Point at the bundled JDK relative to the installation using the + // launcher's ${BASEDIR} token. Unlike passing --jdkhome via a shortcut, + // this resolves however the application is launched - eg. directly or + // via "Open With..." on a file. Forward slashes are tolerated on all + // platforms including Windows. + String basedirHome = "${BASEDIR}/" + jdkhome.replace('\\', '/'); + contents = contents.replace("#jdkhome=\"/path/to/jdk\"", + "jdkhome=\"" + basedirHome + "\""); + contents = contents.replace("#netbeans_jdkhome=\"/path/to/jdk\"", + "netbeans_jdkhome=\"" + basedirHome + "\""); Files.writeString(conf, contents); } diff --git a/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java b/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java index 21fc4e1..53ff41e 100644 --- a/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java +++ b/src/test/java/org/apache/netbeans/nbpackage/TestUtils.java @@ -49,7 +49,9 @@ public static Path buildFakeApp(Path parent, String dirname, String branding) Files.createFile(appBin.resolve(branding)); Files.createFile(appBin.resolve(branding + ".exe")); Files.createFile(appBin.resolve(branding + "64.exe")); - Files.createFile(appEtc.resolve(branding + ".conf")); + Files.writeString(appEtc.resolve(branding + ".conf"), + "#jdkhome=\"/path/to/jdk\"\n" + + "#netbeans_jdkhome=\"/path/to/jdk\"\n"); Files.createFile(platform.resolve("module")); return dir; } diff --git a/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java b/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java index 9622a4e..4238f49 100644 --- a/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java +++ b/src/test/java/org/apache/netbeans/nbpackage/innosetup/InnoSetupPackagerTest.java @@ -74,6 +74,11 @@ public void testImageWithX86_64Runtime() throws Exception { assertTrue(Files.exists(resolve(image, "app", "bin", "app64.exe"))); assertTrue(Files.exists(resolve(image, "app", "etc", "app.ico"))); assertTrue(Files.exists(resolve(image, "app", "jdk", "bin", "java.exe"))); + // bundled JDK is referenced in netbeans.conf relative to ${BASEDIR}, so + // it is found however the launcher is started (not just via a shortcut) + String conf = Files.readString(resolve(image, "app", "etc", "app.conf")); + assertTrue(conf.contains("jdkhome=\"${BASEDIR}/jdk\"")); + assertTrue(conf.contains("netbeans_jdkhome=\"${BASEDIR}/jdk\"")); } }