Platform: Java SWT using Eclipse IDE
Before continuing, I did see a similar issue here on Stack Overflow, 19035407.
Source:
package prjMyapp;
import java.io.InputStream;
public class Myapp
{
public static void main(String[] args)
{
InputStream oStream = Myapp.class.getResourceAsStream("resources/StarTrekLandruRocks.txt");
if (null == oStream)
System.out.println("input stream is null");
else
System.out.println("input stream is NOT null :-)");
}
}
Document Placement
prjMyApp / src / prjMyApp
--> All .java files
--> resources
--> Non-image resources
--> images
--> Image resources (jpg, png)
Interesting Note
I used to use /prjMyapp/resources/whatever.txt and /prjMyapp/images/whatever.ext, however during testing to figure out this problem, I realized that a relative path works too and is better visually and otherwise, hence "resources/StarTrekLandruRocks.txt" instead of the previous "/prjMyapp/resources/StarTrekLandruRocks.txt". As stated, images, and I have quite a few, work as expected on all machines (even a Mac), just not the text file.
Development Machine:
My development machine executes the code perfectly no matter what I do.
CENTOS Box
My CENTOS (Linux) box executes the self contained all inclusive jar file, for which I use ANT to create the file. I can load the text file, if I have the text file as a png extension, but I cannot load the file as a txt extension, same everything else.
Yes, I know that renaming a txt file to a png extension ought never to be done, but I was curious what would happen, as I can load images (jpg and png) with no issues. I found out that getSystemClassLoader just does not like a txt extension. Renaming the extension as png is a hack and fakes the method into working for whatever reason.
I prefer to not do a hack.
Why does the getSystemClassLoader not work directly with txt extension? According to the other post it should, but not on my system.
What is the fix?