I'm trying to run the following application which attempts to load a file (src/main/resources/test.txt) from the classpath:
package com.example;
public class Main {
public static void main(String[] args) {
System.out.println(Main.class.getResource("test.txt"));
}
}
When I do mvn exec:java -Dexec.mainClass=com.example.Main, I get null printed out on the command line.
So how do I get the files in src/main/resources added to the classpath? Note that I ran mvn package, checked the generated target/test.jar, and confirmed that it included test.txt at the top level.