Attempt at fixing wrapper on windows

This commit is contained in:
JFronny 2021-11-11 18:14:51 +01:00
parent 8cfae1564c
commit 2be5da93e2
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
2 changed files with 12 additions and 3 deletions

View File

@ -26,7 +26,7 @@ Steps:
# Using a portable JVM
- Download an [Adoptium JVM build](https://api.adoptium.net/v3/binary/latest/17/ga/windows/x64/jdk/hotspot/normal/eclipse?project=jdk)
- Extract the directory inside the zip file into your wrappers directory
- Create a batch script (launch.bat) with the following content, adjust the JVM path if necessary: `.\jdk-17.0.1+12\bin\java -jar latest-windows.jar`
- Create a batch script (launch.bat) with the following content, adjust the JVM path if necessary: `.\jdk-17.0.1+12\bin\java -jar wrapper.jar`
- Launch the batch script instead of the jar
## Licenses

View File

@ -5,9 +5,12 @@ import io.gitlab.jfronny.inceptum.gson.ComparableVersionAdapter;
import io.gitlab.jfronny.inceptum.model.ComparableVersion;
import io.gitlab.jfronny.inceptum.model.inceptum.InceptumVersion;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
@ -46,9 +49,15 @@ public class MetaHolder {
}
private static Path getDir() {
String p = MetaHolder.class.getProtectionDomain().getCodeSource().getLocation().getPath();
URL url = MetaHolder.class.getProtectionDomain().getCodeSource().getLocation();
String p = url.getPath();
if (p.endsWith(".jar") && !p.endsWith("/build/libs/wrapper-" + VERSION.version + ".jar")) {
return Path.of(p).getParent();
try {
return new File(url.toURI()).toPath().getParent();
} catch (URISyntaxException e) {
e.printStackTrace();
return Path.of(".");
}
} else {
System.out.println("Not running in a jar, using ./run");
return Path.of(".");