In eclipse I have a java project that runs an external program (a .exe) from the main method. This program is in a folder ext under the rot of the project on the same level as the source folder. Now when I run this program from Eclipse it works Like a charm. But when I export a jar file, it does not. I end up with a jar file that does contain the ext folder, but I still get a FileNotFoundException.
I did think of using getClass.getResource(‘path’), but I can’t use this from the static main method.
Any ideas?
To get around the static issue, you can use ClassLoader.getSystemClassLoader().getResource(‘path’)
This may or may not work depending on how you are launching your .exe (it doesn’t really have a file path now, since it is inside the .jar, and I’m guessing it won’t) – having a .exe inside a .jar seems odd to me. Why not leave it outside the .jar, and specify its location with a configuration parameter? This would make much more sense.