I created a simple project using the LWJGL libraries in Intellij IDE. The game runs fine inside the IDE, but I've run into problems when trying to create an executable JAR file. After trying to manipulate Intellij to do it for me and failing, I've switched to using JarSplice.
I've been able to correctly load the LWJGL jar files, as well as all the natives needed to run. However, when launching the file with java -java project.jar
, I receive an error when trying to read my shader source code. I believe the problem is the executable JAR created with JarSplice is not able to find these files. Below is the error I received:
java.io.FileNotFoundException: src/shaders/vert.shader (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at java.io.FileReader.<init>(FileReader.java:58)
at utilities.LWJGLFile.toString(LWJGLFile.java:21)
at utilities.ShaderProgram.loadShader(ShaderProgram.java:42)
at utilities.ShaderProgram.<init>(ShaderProgram.java:26)
at game.LWJGLGame.setupOpenGL(LWJGLGame.java:260)
at game.LWJGLGame.init(LWJGLGame.java:81)
at game.LWJGLGame.<init>(LWJGLGame.java:48)
at main.Main.main(Main.java:22)
The source code at this point in the code looks like this: String source = LWJGLFile.toString("src/shaders/".concat(file));
where file is either "frag.shader"
or "vert.shader"
.
How would I change the file path so the project will work properly on any machine?