0

I have a Java file which refers to a .dll to perform Windows authentication.

In my Java code, I used System.getProperty("java.library.path") to get the PATH, and then I manually appended the PATH of the DLL. It works fine.

But I dont want the DLL to sit in some folder outside. So I moved the DLL file inside a Jar file which contains my Java-class file. I am not sure how to refer to the location of the folder inside my jar.

Any ideas?

Kitswas
  • 1,134
  • 1
  • 13
  • 30
Vivek
  • 1
  • Have you tried using relative paths? `/.dll` – Kitswas Jun 21 '20 at 02:08
  • There are no folders inside jars; this is a common problem for people new to Java. If you _have_ to have something as a file (like you would for a DLL), you have to copy it into a file from the jar resource. – chrylis -cautiouslyoptimistic- Jun 21 '20 at 02:30
  • 1
    Does this answer your question? [How to make a JAR file that includes DLL files?](https://stackoverflow.com/questions/1611357/how-to-make-a-jar-file-that-includes-dll-files) – Moon Jun 21 '20 at 02:46
  • You can't do this. The operating system requires the DLL to be in its file system. – user207421 Jun 21 '20 at 07:03

1 Answers1

0

You can use getClass().getResource() for that!

I recommend to first create a folder in your project dedicated to resources.

Then place your .dll file in there.

Then to refer to it, type something like this:

URL toDLL = getClass().getResource("Resources/someDLL.dll");

Note: This won't work in static methods like in the main() method of the Main class, so for that, type Main.class.getResource() instead.

Here it is in action using IntelliJ:

enter image description here

Devwulf
  • 370
  • 4
  • 11