简体   繁体   中英

How can I make my java code machine independent

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.

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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM