In my gradle java project, if I run ./gradlew run -PappArgs="['file.dat']"
it is compiled and my app succesfully uses the file located in /src/main/resources/
. I have integrated Eclipse with gradle and imported my project into Eclipse. When I run the app in Eclipse with filname specified in the Run Configurations
argument list for the project, it fails to find the file.dat
with this code:
import java.io.InputStream;
import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
final String fileName = args[0];
Scanner scanner = null;
try {
InputStream f = MyClass.class.getResourceAsStream(fileName);
scanner = new Scanner(f, "UTF-8"); // fails here saying f is null
} finally {
if (scanner != null) scanner.close();
}
}
}
Project tree is classic: myproj/src/main/java/MyClass.java
, myproj/src/main/resources/file.dat
and myproj/src/test/java/MyTest.java
.