javadllenvironment-variablesexecutable-jarsigar

“no sigar-winnt.dll in java.library.path” error when using SIGAR


I'm very new to java. I'm developing a tool that checks if your PC meets some set of specifications. This included writing and executing a separate batch file and including an API (SIGAR) for the model of the CPU.

My problem is that when I tried exporting it to Runnable JAR in eclipse, and I ran the resulting JAR from command line, it gave me lots of 'DLL not included in build path' Exceptions. After including the folder that contains the API DLL in the build path, I got similar exceptions. The thing that fixed it was adding the folder containing the DLL to environment variables (PATH) in Advanced System Settings.

Questions:

  1. The JAR now works fine on my computer, but what about the users who download the JAR? Will they also need to add the DLL to environment variables? If so is there a way the JAR can do that for them?

  2. My JAR won't run with a double-click, but will run from command line. Is there any way around this that will carry over to users who download the JAR too?

  3. If the user downloads the tool and can't run it because they don't have the right version of the JRE, will the tool notify them? If not, is there a way around the user having to update JRE or will wrapping as an EXE suffice?

Thanks in advance, much appreciated. Lots of questions.


Solution

  • Q1: The JAR now works fine on my computer, but what about the users who download the JAR? Will they also need to add the DLL to environment variables? If so is there a way the JAR can do that for them?

    You can put a DLL inside a JAR file:

    However, when you distribute a JAR containing a DLL, you then have the problem that different platforms require different DLLs (or whatever). Even with Windows you have the problem of 32 bit versus 64 bit DLLs.

    Q2: My JAR won't run with a double-click, but will run from command line. Is there any way around this that will carry over to users who download the JAR too?

    You cannot address that problem in a JAR file. The "double-click to run" functionality is implemented by the OS. The best way to provide this kind of functionality is using (platform specific) wrapper scripts that are double-clickable.

    Q3: If the user downloads the tool and can't run it because they don't have the right version of the JRE, will the tool notify them? If not, is there a way around the user having to update JRE or will wrapping as an EXE suffice?

    Unless you have a JRE installed, the JAR file is just a passive blob of data. (A ZIP file, actually).

    If the user has a JRE that is too old, then either the JRE will be unable to load any classes in the JAR (because the classfile version number is wrong), or you will get errors because of missing (system) classes.

    The only hope would to do something like providing a wrapper script to launch your application that checked the JRE version before attempting to launch the JAR.


    As a general rule, if you want to do fancy stuff like this you need to distribute your program in an installer, not as a bare JAR file.