I’m using Jar2EXE to generate my EXE files that running on windows without java installed, in my java desktop application i have to upload a file to a dedicated FTP server, the file is in the same Dir where the Jar is running.. previously i have some probems to get the current path of the jar, then i solve this issue with this line:
pathToFile = new File(FtpUploder.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()+"\\File.doc";
I set the jar + File.doc in the same Dir anywhere and its work.
The problem when i generate my exe, the previous line throw NullpointerException then i surrounded it whith try/catch like this:
try{
pathToFile = new File(FtpUploder.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent()+"\\File.doc";
}
catch(NullPointerException e)
{
pathToFile = "C:\\File.doc";
System.out.println("path is null ! lets see the new path : pathToFile ="+pathToFile );
}
the strange problem that is the file is successfully uploaded from “C:\File.doc” , so why its doesn’t work when i set a dynamic path ?
PS: any help will be appreciated(I’m sorry for my english).
Within generated exe file, you can simply call
System.getProperty("application.home")to get the path of generated exe file.Please refer to http://www.jar2exe.com/createdexe/integrate , in the “Overview”.