0

I'm working on a game in java. I started my project in eclipse on a different computer, and now that I exported it out of eclipse on my old computer, copied it to my eclipse workspace on my new computer, imported it in to eclipse, also verified all of my properties are the same on both computers build path java version (SE 1.8), etc. Now all of my Class.class.getResourceAsStream calls are returning null. Even though it works fine on my old computer.

More specifically I have this code

InputStream in=Class.class.getResourceAsStream(file);
BufferedReader reader=new BufferedReader(new InputStreamReader(in));

Where file="guis/guiVertexShader.txt"

So my issue is that Line 1 returns null in eclipse but, if I export my project and make it into a Fat jar, with all of the jars/natives for LWJGL 2 it works fine. Also in eclipse, the below works

InputStream in=new FileInputStream(System.getProperty("user.dir")+"/src"+file);

Although I know I need to use getResourceAsStream so that I can export to a jar. Any ideas?

  • getResourceAsStream reads (as the name implies) a Resource from the current classpath. Propably you should take a look at https://stackoverflow.com/questions/2161054/where-to-place-and-how-to-read-configuration-resource-files-in-servlet-based-app – triplem Apr 29 '21 at 22:00

1 Answers1

0

I seem to have fixed it, the issue was I didn't have a compatible jre with Java 1.8 installed on my new computer. As soon as I installed it (Java 8) and added the JRE to eclipse it ran fine in both eclipse and in a Fat jar