I have read every single question and answer regarding this topic and I have tried a multitude of the suggested solutions, none of which are working, currently I am trying to use the URL resource method but url always returns null. Here is my current pseudo setup:
/src/java/pkg/name/is/long/meatpackage/MyClassFile.java
/src/java/pkg/name/is/long/meatpackage/myresources/myresourcefile.txt
@SuppressWarnings("rawtypes")
Class thisClass = Class.forName("pkg.name.is.long.meatpackage.MyClassFile");
ClassLoader cLoader = thisClass.getClassLoader();
//note, I have tried a plethora of variations to the path for the file, this is just one example
URL url = cLoader.getResource("pkg/name/is/long/meatpackage/myresources/myresourcefile.txt");
System.out.println("Found the file!!: " + url);
Seriously, it can't be THIS hard to include a text file in your jar and access it at runtime can it?
When I list the jar it shows that the file is in pkg/name/is/log/meatpackage/myresources/myresourcefile.txt.
Another approach I have tried is:
//along with multiple path combinations for the file the InputStream is always null.
//multiple paths include but are not limited to:
// "pkg/name/is/long/meatpackage/myresources/myresourcefile.txt"
// "/pkg/name/is/long/meatpackage/myresources/myresourcefile.txt"
// "/myresources/myresourcefile.txt"
// "/myresourcefile.txt"
// "myresourcefile.txt"
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("myresourcefile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(is));