简体   繁体   English

如何使用相对路径加载.dll-Java

[英]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? 我如何以某种方式加载.dll,以便在将项目传输到另一台计算机时,应用程序在不更改.dll路径的情况下仍能正常运行?

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). 请以非常基本的术语(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. 如果您知道dll文件相对于应用程序启动点的位置(即jar文件),则可以获取当前的工作目录,然后以这种方式组合一个相对路径。

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: 如果dll与jar处于同一文件夹中,则可以按以下方式找到它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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