2

I built an executable jar file (test.jar) that depends on some jar libraries and dll.

at the start it shows a JFileChooser dialog and the user must selects a file. after that it calls a method and reads the selected file using jar/dll libraries. At the end of precess it shows output dialog.(using JOptionPane) and finally creates a dialog that means finished!

it runs in netbeans successfully and there isn't any problem for using JNI. also i could create a batch file(test.bat) and run the jar file. it's OK.

But when i double click on executable jar file, shows the fileChooser and after selecting a file nothing happens. by this way it shows final dialog! i put my files likes this:

NewFolder

 test.jar
 test.bat
 lib0.dll
 lib1.dll
 lib

   lib2.jar
   lib3.jar

what is the problem? help me please. is my problem related to load dll files and its path ? My problem seems to be match with this: https://stackoverflow.com/questions/17811376/dll-files-not-loaded-if-executing-jar-file

Ali
  • 113
  • 2
  • 10
  • SORRY! VTCd to wrong link. It should be http://stackoverflow.com/questions/17811376/dll-files-not-loaded-if-executing-jar-file – nanofarad Aug 10 '13 at 19:52
  • Please confirm for me that `javaw -jar myjar.jar` gives the same issue as when you double click it. – Xabster Aug 10 '13 at 19:58
  • Open a command prompt. Type "ftype jarfile" and reply with the output. If you're not on Windows, tell us. – Xabster Aug 10 '13 at 20:10
  • yes it works with both `javaw -jar test.jar` and `java -jar test.jar` in batch file – Ali Aug 10 '13 at 20:12
  • I meant literally type "ftype jarfile". Don't change "jarfile" to "C:\test.jar" – Xabster Aug 10 '13 at 20:17
  • sorry! removed. output: `jarfile="C:\Program Files\Java\jre u25\bin\javaw.exe" -jar "%1" %*` – Ali Aug 10 '13 at 20:20
  • Okay, now write "java -version" and paste what it shows. – Xabster Aug 10 '13 at 20:23
  • it shows: <`java version "1.7.0_25" `> <`java(TM) SE Runtime Environment (build 1.7.0_25-b16)`> <`Java HotSpot(TM) Client VM (build 23.25-b01,mixed mode,sharing)`> – Ali Aug 10 '13 at 20:31

1 Answers1

0

It appears that the java command you're running is a x86 (32 bit) version and that the javaw you have associated with jarfiles in windows is x64. This is a mismatch and the reason why one of them will load the dll, and the other will not.

If it works in console but not on double click it would appear that the library is 32 bit. Is this correct?

If so, and you would like to change windows' association on double to a x86 version, you need to follow these instructions:

http://windowstipoftheday.blogspot.dk/2005/10/setting-jar-file-association.html

Note: the instructions link to an x64 version of javaw. You need to find the one in "C:\program files (x86)\java".

Xabster
  • 3,710
  • 15
  • 21
  • yes my dll files are 32 bit. and i had to configure 32 bit jdk in netbeans Java Platforms. thanks a lot. i will search your solution. – Ali Aug 10 '13 at 20:56
  • It's fairly simple. Just follow the steps but go to "C:\Program Files (x86)\Java" and find javaw instead of the path in the instructions. – Xabster Aug 10 '13 at 21:00
  • It solved! i typed this line in command prompt... `jarfile="C:\Program Files (x86)\Java\jre7 u25\bin\javaw.exe" -jar "%1" %*` from this link: http://stackoverflow.com/questions/354664/executing-a-jar-on-vista-with-a-double-click and now i execute the jar file with double click completely of course the JOptionPane dialog was created!! In fact i can load 32 bit dll files from executable jar file – Ali Aug 10 '13 at 21:26
  • to Xabster: your explanation in answer is complete. however i could not follow instructions!! what is the difference between result of instructions and `Open With...` by right click the jar file!? – Ali Aug 10 '13 at 21:55
  • If you do the "Open With..." you're not providing information to Windows on how to actually run the .jar file. It doesn't know about the -jar parameter, or that is should put commandline options at the end. That is what you tell it with the "-jar %1 %*" part of it. Are you on Windows 7? The instructions are for Windows 7. Do you still need help to solve this, or are you just asking because you're curious? – Xabster Aug 10 '13 at 22:27
  • yes, i am in windows 7 x64 and i asked with curiosity. the instructions was unclear for me. i don't think it is for windows 7. because i could not find the `File Types` tab from `Tools` menu in `Windows Explorer`! it solved using the command line... of course it seems there is an alternative instructions in windows 7: http://www.dkszone.net/how-to-change-default-program-of-file but i am not sure that works! – Ali Aug 11 '13 at 05:28