When the uber jar created with spring-boot-maven-plugin:3.2.1 (repackage goal) is put on a WSL (Windows subsystem for Linux) network drive, the following error is emitted when running the jar:
$ java -jar \\wsl$\debian\spring-boot_3.2.1-uber-jar-issue-0.0.1.jar
Exception in thread "main" java.lang.ClassNotFoundException: be.pdn.issue.sbmp.Main
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:104)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:534)
at java.base/java.lang.Class.forName(Class.java:513)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:88)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
This is not the case when the uber jar is created with spring-boot-maven-plugin:3.1.7
$ java -jar \\wsl$\debian\spring-boot_3.1.7-uber-jar-issue-0.0.1.jar
If you see this it works
As a workaround it is possible to set
Tested on Windows 11 with Java 21. Example project to reproduce: spring-boot-uber-jar-issue.tar.gz.
Comment From: wilkinsona
I'm not familiar with WSL, unfortunately, and I don't think anyone on the Spring Boot team has used it. Is \\wsl$\debian\spring-boot_3.2.1-uber-jar-issue-0.0.1.jar pointing to a jar file on the Linux filesystem from within Windows? If so, does mounting that path to a Windows drive help to work around the problem? I also wonder if other UNC paths are affected or, perhaps, the $ here is crucial (possibly due to URL encoding).
Comment From: pdeneve
Affirmative, \\wsl$\debian\spring-boot_3.2.1-uber-jar-issue-0.0.1.jar is pointing to a jar file on the Linux filesystem from within Windows.
I've tested a couple of things and it seems the issue is the UNC path, not the dollar sign. Mapping the network share as a drive works around the issue. Here's the output of my tests:
C:\d\apps\jdk\jdk-21.0.1\bin>.\java -jar \\wsl.localhost\Debian\home\philippe\spring-boot_3.1.7-uber-jar-issue-0.0.1.jar
If you see this it works
C:\d\apps\jdk\jdk-21.0.1\bin>.\java -jar \\wsl.localhost\Debian\home\philippe\spring-boot_3.2.1-uber-jar-issue-0.0.1.jar
Exception in thread "main" java.lang.ClassNotFoundException: be.pdn.issue.sbmp.Main
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:104)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:534)
at java.base/java.lang.Class.forName(Class.java:513)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:88)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
C:\d\apps\jdk\jdk-21.0.1\bin>.\java -jar Z:\home\philippe\spring-boot_3.2.1-uber-jar-issue-0.0.1.jar
If you see this it works
C:\d\apps\jdk\jdk-21.0.1\bin>.\java -jar \\192.168.0.4\storage\tmp\spring-boot_3.2.1-uber-jar-issue-0.0.1.jar
Exception in thread "main" java.lang.ClassNotFoundException: be.pdn.issue.sbmp.Main
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593)
at org.springframework.boot.loader.net.protocol.jar.JarUrlClassLoader.loadClass(JarUrlClassLoader.java:104)
at org.springframework.boot.loader.launch.LaunchedClassLoader.loadClass(LaunchedClassLoader.java:91)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:534)
at java.base/java.lang.Class.forName(Class.java:513)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:88)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
C:\d\apps\jdk\jdk-21.0.1\bin>.\java -jar \\192.168.0.4\storage\tmp\spring-boot_3.1.7-uber-jar-issue-0.0.1.jar
If you see this it works
Explanation on the shares used:
1. It's possible to access a WSL linux instance via \\wsl.localhost, rather than via \\wsl$. I've used \\wsl.localhost this time to rule out the issue is related to the dollar sign.
2. Z:\ is the drive I've mounted the WSL share on.
3. \\192.168.0.4 is an external Windows share, i.e. not WSL, to rule out the issue is related to WSL.