Cant figure out his error... Only happens on other peoples computers.

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: com.melloware.jintellitype.JIntellitypeException: Could not load JIntellitype.dll from local file system or from inside JAR
        at com.melloware.jintellitype.JIntellitype.<init>(JIntellitype.java:114)
        at com.melloware.jintellitype.JIntellitype.getInstance(JIntellitype.java:174)
        at CaptureScreen.registerHotkeys(CaptureScreen.java:163)
        at CaptureScreen.<init>(CaptureScreen.java:100)
        at CaptureScreen.main(CaptureScreen.java:199)
        ... 5 more
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\B\AppData\Local\Temp: Can't find dependent libraries
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.System.load(Unknown Source)
        at com.melloware.jintellitype.JIntellitype.<init>(JIntellitype.java:99)
        ... 9 more

Thats the error that shows up on my friends computer. Basically what my program does is extract a dll file from itself and put it in the temp folder. It then loads it. (this is a windows key hook)

Anyways, my program runs flawlessly on my computer, but on my friends or anyone elses it throws this error at me. Does anyone have any idea what might be going on and why it does not happen on my computer?

Edit: This also makes it really hard for me to test… as I have no way to know if I fixed it or not.

I just realized that I also get that error, but only if I run the program from the command line. However, if I double click the jar and run it that way, the program runs fine with no issues.

However, my friend was trying to run the jar like that and it didnt do anything, and when we ran it from the command line it gave him that error… so confused.

Sorry if i’m obvious, but:

You have some code made on IntelliJ that runs just fine on your computer, but when you try to run it on another computer it gives out some error.

Have you checked if that JIntellitype.dll is really inside the jar? Also, it is trying to load from C:\Users\B\AppData\Local\Temp

yea, I know its trying to load from there because thats where I set it to load from and to extract the dll to. I tried manually putting the dll in the jar but still no dice.

“Can’t find dependent libraries”

Looks like that DLL depends on other DLLs which are installed on your system path when using IntelliJ, but not on others nor when you run it from command prompt.

Best way to test if it’s true is to create a File object of that temp location and see what the ‘exists()’ method return. If the DLL file exists, that means the above assumption is correct. If it returns false, then I’m incorrect :slight_smile:

Why is everyone assuming it’s IntelliJ? IDEA has no native components, if it were an IntelliJ thing, it would be com.jetbrains, and the only time you ever run into IntelliJ dependencies are at compile time if you use @NotNull and don’t use some other JSR303 implementation.

OH! JIntellitype.dll is something completely unrelated from IntelliJ XD

Googling it, it seems to allow to access Windows specific behavior in your Java applications. It also seems that there is only 1 DLL needed, that one.

@OP, could you post some code on how you load the DLL?

It’s true that some errors/exceptions from java can still let the application to run but lost of native?

extract to temp folder… don’t tell me that your both OS are not same.

yea. here is how I am loading. first off, I attempt to extract the .dll from my jar and place it in the temp directory. I then load it after doing that. However, I still get that error. I also found that my extracting is creating a 0kb file… so its not really extracting it from the jar. or something.

AccessController.doPrivileged(new PrivilegedAction<Void>()
		{
			@Override
			public Void run()
			{
				String dllName = "JIntellitype.dll";
				File tmpDir = new File(System.getProperty("java.io.tmpdir"));
				File tmpFile = new File(tmpDir, dllName);
				//if (!tmpFile.exists())
				{
					try
					{
						InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(dllName);
						OutputStream out = new FileOutputStream(System.getProperty("java.io.tmpdir"));

						byte[] buffer = new byte[8192];
						int bytesRead;
						while ((bytesRead = in.read(buffer)) != -1)
						{
							out.write(buffer, 0, bytesRead);
						}

						in.close();
						out.close();

					} catch (Exception e)
					{
						e.printStackTrace();
					}

				}
				System.load(tmpFile.getAbsolutePath());
				return null;
			}
		});

Aha! You are supposed to create a FileOutputStream on that File object! Not the folder! XD

Yea, I got it figured. That code I posted was causing a different issue. I forgot that I edited it. The so I reversed back to what I did have when it was writing the file correctly to begin with. Turns out it was not finding the file in my jar. I needed to have the .dll placed next to my class files and once I tried that it seemed to work.

Either way, thanks for your guys help!

Or you could put the DLL at the root of the JAR file and use getResourceAsStream("/" + dllName);