For my text maze game, Eclipse
can find the text file and run it properly, but when I convert the jar
of the project to an exe
, the exe
cannot find the file. Strange thing is that both the jar file I created and the exe
are in the same directory, yet the jar
file runs perfectly whereas the exe file does not. Why is this?
Here is my code:
try {
//Find the file, create the maze, etc.
}
// Exceptions
catch (FileNotFoundException e) {
File file = new File("maze.txt");
System.out.println(file.canRead());
System.out.println(file.getAbsoluteFile().exists());
}
Both of the two prints output false when I run the exe
, even though all of the files are in the same directory and it works for the Jar
file. Why is this? I am using IExpress
to convert to an exe
by the way.
You can use Launch4j as it is easy to use
Launch4j is a cross-platform tool for wrapping Java applications distributed as jars in lightweight Windows native executables. The executable can be configured to search for a certain JRE version or use a bundled one, and it's possible to set runtime options, like the initial/max heap size. The wrapper also provides better user experience through an application icon, a native pre-JRE splash screen, and a Java download page in case the appropriate JRE cannot be found.