I noticed that I am not able to get a resource when I run/debug a modularized Java 11 application within IntelliJ, but when I use Gradle's run
task it works fine.
LoadResource.java
package com.example;
public class LoadResource {
public static void main(String ... args) {
new LoadResource().run();
}
private void run() {
System.out.println("TEST");
final var resource = getClass().getResource("Foo.txt");
System.out.println(resource.toExternalForm());
}
}
module-info.java
module LoadResource {
exports com.example;
}
build.gradle
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
mainClassName = 'LoadResource/com.example.LoadResource'
UPDATE: Adding
run {
doFirst {
println commandLine
}
}
shows that Gradle apparently executes [C:\Program...\bin\java.exe, -Dfile.encoding=windows-1252, -Duser.country=US, -Duser.language=en, -Duser.variant, -cp, D:\xxx\load-resource\build\classes\java\main;D:\xxx\load-resource\build\resources\main, null]
.
You can find my sample project here.