0

I have written a very small java code on Eclipse which will automate a small process of logging into a web system. The employees of my company use this web system to connect to office network if they are working from home.

I have converted my java project on Eclipse into an exe file, my intention is to log into that system by just a double click on the exe file.I have parameterized the userID and password and have stored it in an excel file on my local machine.

The problem am having is, My exe file will not run in any other systems except mine as my code is referring to the excel file(which has userID and password) path on my local machine. I would greatly appreciate the developers on this forum who could help me out to come up with a solution for this problem.

  • 1
    Use JAR instead of EXE? exe is only for windows. see http://stackoverflow.com/questions/2861592/possible-to-run-jar-file-on-any-os – Lucky Feb 21 '17 at 12:56
  • 1
    Compiling to an exe defeats one of the main benefits of using the JVM in the first place. Just keep it as a jar and bundle it with a bat for windows to ease launching. – Carcigenicate Feb 21 '17 at 12:58
  • Why not just use C++? It is just as easy as Java ;-) – TungstenX Feb 21 '17 at 13:00
  • 1
    I think all the above comments have missed the main part of the question: *"The problem am having is, My exe file will not run in any other systems except mine as my code is referring to the excel file on my local machine."* – Steve Smith Feb 21 '17 at 13:41
  • What about looking for the excel file in a well defined folder like `C:\Users\\my-tool\credentials.xls`. Or maybe look for it in the same dir as the executable? – thomas.mc.work Feb 21 '17 at 14:18
  • Without seeing the code that you're using to load the file, it's hard to say what you need to change. Also, the question is confusing because, as other comments have mentioned, Java does not make Windows `.exe` – E-Riz Feb 21 '17 at 14:35
  • @thomas.mc.work Many thanks for that solution. As you said in my code I am looking for the excel file from a folder like C:\Users\\my-tool\credentials.xls. But lets say, I share this exe file and excel file with my colleague, his will be different and the program will fail due to this. I want a solution for this. TIA – Shawn Dsouza Feb 21 '17 at 14:49
  • Thank you all for your useful comments. Much appreciate. – Shawn Dsouza Feb 21 '17 at 14:50
  • You might, instead, place your `credentials.xls` file inside the jar file and find it on the classpath. See [Java resource as file](http://stackoverflow.com/questions/676097/java-resource-as-file) – Jon Sampson Feb 21 '17 at 23:19
  • @ShawnDsouza I've added that plus some more as an answer. – thomas.mc.work Feb 22 '17 at 07:26

1 Answers1

0

What about looking for the excel file in a well defined folder like C:\Users\\my-tool\credentials.xls. Or maybe look for it in the same dir as the executable?

You can get the path of the home folder of the current user with this command:

String homeDir = System.getProperty("user.home");

With that you cann assemble your custom lookup path:

Path xlsPath = Paths.get(System.getProperty("user.home"))
    .resolve("my-tool")
    .resolve("credentials.xls");
thomas.mc.work
  • 6,234
  • 2
  • 22
  • 40
  • Thanks a million! You gave me the solution I was looking for. It worked... Thank you all for your precious comments. – Shawn Dsouza Feb 22 '17 at 09:34