简体   繁体   中英

How to load a .dll using relative path - Java

How would I load a .dll in a way that when the project is transferred to another computer, the application would still work perfectly without changing the .dll path?

I read some threads on this website who tried to answer that question it seems, but all of them went over my head. Please explain in very basic terms (ELI5).

Thank you.

If you know where the dll file will be located in relation to the launching point of the application (ie the jar file), you can get the current working directory, then put together a relative path that way.

Get the current working directory using this line:

String directory = new File(".").getCanonicalPath();

If the dll is in the same folder as the jar then you can locate it like this:

File dllPath = new File (directory+File.separator+"example.dll");

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