I want to use gradle to create from my code .jar, and then from .jar create .exe. I have a simple Java code
package project;
public class main {
public static void main(String[] args) {
System.out.println("hello");
}
}
and a build.gradle file.
plugins {
id 'java'
id 'idea'
id 'com.github.johnrengelman.shadow'
id 'edu.sc.seis.launch4j'
}
jar.enabled = false
group 'project'
version '1.0-SNAPSHOT'
java {
sourceCompatibility = 1.8
}
repositories {
}
dependencies {
}
shadowJar {
archiveBaseName.set('toJarToExeFat')
archiveVersion.set('0.1')
archiveClassifier.set('')
manifest {
attributes 'Main-Class': 'project.main'
}
}
tasks.shadowJar.dependsOn tasks.build
createExe {
outfile = 'test.exe'
mainClassName = 'project.main'
jar = "C:/work/java/toJarToExe/build/libs/toJarToExeFat-0.1.jar"
}
tasks.createExe.dependsOn tasks.shadowJar
It works, but when I run .exe, I get "This application requires Java Runtime Environment 1.8.0".
I was expecting to receive .exe as if I wrote this program in C
According the error message I would say JRE not installed on Machine where you run your "exe". I had the same problem with last version (java 21), which was installed only "inside" IntellijIDEA and it has been resolved as soon as I intalled it on my system.