[FIXED] Cannot use JIntellitype with double-clickable jar

Feature Requests, Comments, Bugs, and Suggestions on the JIntellitype Java API.

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Thu Aug 06, 2009 1:00 pm

Hmm interesting discussion.
It's not difficult to determine a path, but jar files are generally thought to be path independent - that adds a twist or two ;-)
To your idea of packing the dll into the jar: great Idea, never thought of that. I actually might do that myself because that would reduce my project to basically one file (excluding documentation and user content, of course).
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Dark$hadow » Thu Aug 06, 2009 3:47 pm

I'm not sure it's possible to include the dll in the JAR...

It seems to me that include JAR into other JAR is not possible (?)

But thanks to Melloware, the problem is solve by putting the dll in the same directory than the JAR :)
Dark$hadow
 
Posts: 9
Joined: Tue Aug 04, 2009 7:01 am

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Melloware » Thu Aug 06, 2009 4:52 pm

Dark$hadow,

Just let me know if you want me to add your app Clic2Dial and a link on the Jintellitype website when you are complete.

DJGummikuh, If you figure out a way to load the DLL from inside the JAR file let me know I will gladly add that info to the website also.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11020
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Dark$hadow » Fri Aug 07, 2009 2:27 am

Why not :)

I'll tell you when the project will be released.

Thanks for your help !!!

Dark.
Dark$hadow
 
Posts: 9
Joined: Tue Aug 04, 2009 7:01 am

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Fri Aug 07, 2009 5:05 am

Ok I did a little research and tried some things (on one of my famous bus trips :D) and this is what I came up with.
It seems that it's impossible to load JNI files from within .jar files since the Windows DLL loader needs to be able to physically access the library using only file system tools (i.e. no jar tool to access files within a jar file). Therefore, the only way possible whould be to automatically extract the dll file from the jar file prior to loading it. Sorry. I hoped it could be done from inside the jar directly
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Melloware » Fri Aug 07, 2009 5:55 am

DJGummikuh wrote:Ok I did a little research and tried some things (on one of my famous bus trips :D) and this is what I came up with.
It seems that it's impossible to load JNI files from within .jar files since the Windows DLL loader needs to be able to physically access the library using only file system tools (i.e. no jar tool to access files within a jar file). Therefore, the only way possible whould be to automatically extract the dll file from the jar file prior to loading it. Sorry. I hoped it could be done from inside the jar directly


That is OK. I remember researching this like two years ago when i first released Jintellitype and came to the same conclusion. I was just figuring a fresh set of eyes looking at the problem might have the solution. :) It's not the end of the world to have the DLL next to the JAR.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11020
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby TheWhite » Tue Aug 25, 2009 4:23 pm

Too bad I wasn't here earlier, I would have told you, you must extract/have it out of the Jar file first.

You can use the fact that inside the jar file it is a resource as an advantage by using this function that I made:

Code: Select all
/**
    * Extracts the resource with the given name into the destination file.
    * If for some reason the program is unable to write the destination file,
    * an error presents before forcing the application to close.
    *
    * @param name The name of the resource.
    * @param dstFile The destination file where the resource will be extracted to.
    *
    * @return The absolute path of the destination file.
    */
   public String extractResource(String name, File dstFile) {
      try {
         InputStream resource = getClass().getResourceAsStream(name);
         FileOutputStream outStream = new FileOutputStream(dstFile);
         byte[] buffer = new byte[1024];
         int bytes;
         while ((bytes = resource.read(buffer)) != -1) {
            outStream.write(buffer, 0, bytes);
         }
         outStream.close();
         resource.close();
      } catch (IOException e) {
         JOptionPane.showMessageDialog(this, "Unable to write to: "+   dstFile.getAbsolutePath(),
               "ERROR: Permissions", JOptionPane.ERROR_MESSAGE);
         System.exit(-1);
      }

      System.out.println("Successfully extracted "+dstFile.getAbsolutePath());
      return dstFile.getAbsolutePath();
   }


If you make the param File dstFile = new File(filename); without the actual path (just the filename), it will extract it next to the .jar file where you can load it just fine using the existing code. When you go to clean up, you can have it delete the file so its just your 1 runnable jar thats left, at the beginning and the end. :)

The beauty of this is that it will work when using a runnable jar and without, so you can test and create seamlessly.
TheWhite
 
Posts: 7
Joined: Tue Aug 25, 2009 4:14 pm

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby arnefm » Thu Dec 16, 2010 7:49 pm

Hi. I am having a problem with finding the DLL when running my application from a jar-file.
My application copies the dll from its resources to users temp directory.
Everything works as it should when I run the application in Netbeans IDE, but when I execute
the JAR-file the DLL is not found. I have tried hardcoding the path to the DLL like this:

JIntellitype.setLibraryLocation("C:\\Users\\Username\\AppData\\Local\\Temp\\JIntellitype64.dll");

This does for some reason not work. I have, of course, verified that the DLL actually exists in this directory.

Is this a known issue, or have I overlooked something?
arnefm
 
Posts: 5
Joined: Thu Dec 16, 2010 7:21 pm
Location: Trondheim, Norway

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Melloware » Thu Dec 16, 2010 10:08 pm

Hmmm that should work as long as you call it before calling any other static method on JIntellitype.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11020
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby arnefm » Fri Dec 17, 2010 6:06 am

It is the first static method i call. I have now tried with other directories ("C:\\JIntellitype64.dll", ".\\lib\\JIntellitype64.dll" etc.). Right after setting the library location I run:

if (JIntellitype.isJIntellitypeSupported()) {
JIntellitype.getInstance().addHotKeyListener(this);
System.out.println("DLL found!");
}

Edit:
File f = new File(System.getProperty("java.io.tmpdir") + "JIntellitype64.dll");
System.out.println(f.getAbsolutePath());
if (f.exists())
System.out.println("File found!");
JIntellitype.setLibraryLocation(f.getAbsolutePath());
else
System.out.println("File does not exist");

In both cases (running from Netbeans and running the JAR) the file is found by f.exists().
arnefm
 
Posts: 5
Joined: Thu Dec 16, 2010 7:21 pm
Location: Trondheim, Norway

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Melloware » Fri Dec 17, 2010 6:33 am

Hmmm here is the source code:

http://code.google.com/p/jintellitype/source/browse/trunk/src/main/java/com/melloware/jintellitype/JIntellitype.java?r=11

In the constructor you see I try and load the library from System32 or local run directory. If that fails I then check if the LibraryPath was set and load that.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11020
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby arnefm » Fri Dec 17, 2010 8:04 am

I just found out what is wrong. For some reason Netbeans uses the 64-bit JRE when running my application, while when i run it from command line using "java- jar MyApp.jar" a 32-bit JRE is used... How is this possible? I used System.getProperty("os.arch"); to check this. When running in Netbeans it returned "amd64", but the JAR returned "x86".

I started learning Java two days ago so I am still new to all this. Could you please help me fix this?

Edit:
I have som additional questions; Will Java code compiled with 32-bit be fully compatible with 64-bit JVM? Will I be able to load the 32-bit library (JIntellitype.dll) in a 64-bit JVM?
I would love to have my application working in both 32 and 64-bit environments.
arnefm
 
Posts: 5
Joined: Thu Dec 16, 2010 7:21 pm
Location: Trondheim, Norway

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Melloware » Fri Dec 17, 2010 8:55 am

32 bit JVM must use the 32 bit DLL.

64 bit JVM must use the 64 bit DLL.

In Netbeans you control the JVM at the project level. At the command line it is using whatever Java version is in your path.

Run this at the Command Prompt.

Code: Select all
java -version


It will show you what your default Java is runnign on our path. If you need to run a specific version at the command line create a BAT file that points specifically to the right JVM when calling your app.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11020
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby arnefm » Fri Dec 17, 2010 9:19 am

Thank you for your help! I think I will include both 32 and 64-bit libraries in my JAR, and copy to temp based on the result of System.getProperty("os.arch").
This is a really great library! By far the easiest way I have found to use global hotkeys in java applications.
arnefm
 
Posts: 5
Joined: Thu Dec 16, 2010 7:21 pm
Location: Trondheim, Norway

Re: [FIXED] Cannot use JIntellitype with double-clickable jar

Postby Melloware » Fri Dec 17, 2010 10:32 am

Awesome!!!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Melloware Inc.
http://www.melloware.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
User avatar
Melloware
Site Admin
 
Posts: 11020
Joined: Thu Dec 01, 2005 10:24 pm
Location: Philadelphia, Pennsylvania USA

PreviousNext

Return to JIntellitype

Who is online

Users browsing this forum: No registered users and 1 guest