[FIXED] Cannot use JIntellitype with double-clickable jar

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

[FIXED] Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Mon Jul 27, 2009 2:53 am

Hello!

First and foremost, thank you for this great library.
I started a tiny project "RadiS" (http://radis.sf.net) and could not have done it without this libary.
However, there is a thing I would like either changed or explained.

Right now, the only way to start radis is to use a .bat file. I don't like this. I would like to be able to simply provide the .jar, which is double-click-able.
Unfortunately, there is no way to provide -Djava.library.path in the Manifest. I Googled the problem and found out that this property can be set at runtime via the System.setProperty("java.library.path", "javalibs"); command. However, this does not work with JIntellitype. My guess is that the Java Wrapper tries to load JIntellitype native dll as soon as the JVM starts up. If it could wait until the first call of getInstance() (lazy initialization) it would allow me to initialize the System property from within the code and therefore make my jar double-clickable.

Thanks in advance,
DJGummikuh
Last edited by DJGummikuh on Fri Jul 31, 2009 7:40 am, edited 2 times in total.
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: Cannot use JIntellitype with double-clickable jar

Postby Melloware » Mon Jul 27, 2009 6:11 am

Let me look into this and get back to you...
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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: Cannot use JIntellitype with double-clickable jar

Postby Melloware » Mon Jul 27, 2009 7:05 am

OK it does look like I don't call System.loadLibrary("JIntellitype"); until you call JIntellitype.getInstance() the first time.

http://melloware.com/products/jintellitype/xref/com/melloware/jintellitype/JIntellitype.html

Also can you try and put the DLL in Windows\System32 directory so see if that at least gets you past the problem? then we can figure out why setting the library path is not working.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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: Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Mon Jul 27, 2009 7:20 am

Ok I looked into the source code you provided (should've done that before perhaps :oops: ) And you are right, the loading is triggered by getInstance().
I just digged a little deeper and found out that System.setProperty does not work as java.library.path is appearantly not "settable".
http://forums.sun.com/thread.jspa?threadID=627890 seems to cover this problem. I'm trying their solution and will report back here.
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Mon Jul 27, 2009 7:29 am

Ok I now can load the library in a rather ugly way, using the following code sniplet:
Code: Select all
File f = new File(".");
      String library = f.getAbsolutePath();
      library = library.substring(0, library.length() -1);
      library += "javalibs/JIntellitype.dll";
      System.load(library);

Unfortunately, JIntellitype now does not work since it tries to load the library itself.

And to your idea of putting the dll into the win32 folder: I already can use the library, using my beforementioned .bat file. When Setting java.library.path during the jvm call, the library works just fine. Now is all about trying to get rid of the .bat file :)
Anyways, thank you for your effort
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Mon Jul 27, 2009 7:46 am

Ok I "Solved" this problem for my case now by altering your source code and commenting out line 95. If a better way can be found I'd prefer it but for now, JIntellitype does what I need it to do :)
Thank you for your support. Really great library you have here :)

Edit: Btw: even though urls are case insensitive the project is called RadiS, not Radis ;-)
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: Cannot use JIntellitype with double-clickable jar

Postby Melloware » Mon Jul 27, 2009 8:08 am

DJGummikuh wrote:Ok I "Solved" this problem for my case now by altering your source code and commenting out line 95. If a better way can be found I'd prefer it but for now, JIntellitype does what I need it to do :)
Thank you for your support. Really great library you have here :)

Edit: Btw: even though urls are case insensitive the project is called RadiS, not Radis ;-)


OK I will fix that!

Yeah I didn't realize from an executable JAR this would be such an issue. Maybe we can figure out a better way around it.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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: Cannot use JIntellitype with double-clickable jar

Postby DJGummikuh » Mon Jul 27, 2009 9:01 am

A possible solution might be providing a static "setLibraryLocation(String path)" or similar method that takes the (relative/absolute) path to the .dll file. Then, the constructor can check whether or not that path has been set and either use your current way of loading the library or load the library explicitly via the System.load(String path); method.
Just a suggestion
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

Re: Cannot use JIntellitype with double-clickable jar

Postby Melloware » Tue Jul 28, 2009 8:11 am

OK i just uploaded 1.3.2 with the static setLibraryLocation.

Also I added your credit to the Project Team...

http://melloware.com/products/jintellitype/team-list.html

and to the changes report...

http://melloware.com/products/jintellitype/changes-report.html
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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 DJGummikuh » Fri Jul 31, 2009 12:27 am

thank you very much (for both the quick fixing and adding to contributor page ;-) ), I will try out your new version today.
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

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

Postby DJGummikuh » Fri Jul 31, 2009 2:10 am

Ok i tried it out and I am sorry to say, your Fix didn't fix it :-)
The constructor calls the wrong method in the case the library path was set. loadLibrary() only takes the library name, not its path. To load a library including its path you have to use System.load(). Also, it would be great if you could also take care of handling both absolute and relative paths to the library in your setLibraryLocation method.
Here is how I adjusted your code the way I would think it could work:
The constructor:
Code: Select all
   private JIntellitype() {
      // Load JNI library
      try {
         LOG.info("Loading JIntellitype DLL");
         if (getLibraryLocation() != null) {
            LOG.info("DLL Path = " + getLibraryLocation());
            System.load(getLibraryLocation());
         } else {
            System.loadLibrary("JIntellitype");
         }
         
         LOG.info("Initializing JIntellitype library");
         initializeLibrary();
      } catch (UnsatisfiedLinkError ex) {
         throw new JIntellitypeException(ex);
      } catch (RuntimeException ex) {
         throw new JIntellitypeException(ex);
      }
   }

And the setLibraryLocation method:
Code: Select all
   /**
    * Sets the libraryLocation.
    * <p>
    * @param libraryLocation The libraryLocation to set. Can be either a relative or an absolute path.
    */
   public static void setLibraryLocation(String libraryLocation) {
       //Ok the absolutepath check could be nicer but it does the trick :)
       if(!libraryLocation.substring(1,2).equals(":")) {
          //no : as second char means we're on a relative path
          //therefore, we have to get our current path first, then
          //add the relative path given to it.
          File f = new File(".");
      String library = f.getAbsolutePath();
      library = library.substring(0, library.length() -1);
      library += libraryLocation;
      JIntellitype.libraryLocation = library;
       } else {
          //absolute path, no further calculation needed
          JIntellitype.libraryLocation = libraryLocation;
       }
   }

I know that setLibraryLocation has quite a hackish accent now, perhaps this can be made more beautiful but it does the trick ;-)
I have tested the code and it works like expected.

No matter how you decide, thanks anyways for your quick response :)
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

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

Postby DJGummikuh » Fri Jul 31, 2009 2:14 am

Oh I forgot something. In your latest release, you didn't pack the commons-logging jar along. I know that you need it but new users might be confused about the errors your library throws without it :)
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

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

Postby Melloware » Fri Jul 31, 2009 5:58 am

DJGummikuh wrote:Oh I forgot something. In your latest release, you didn't pack the commons-logging jar along. I know that you need it but new users might be confused about the errors your library throws without it :)


HA! Yeah, I usually never include that JAR with it. I am actually thinking of tearing out commons-logging because it really doesn't log that much information and it has caused much confusion!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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 DJGummikuh » Fri Jul 31, 2009 6:36 am

And for my post before that? The one with the code suggestions?
DJGummikuh
 
Posts: 13
Joined: Mon Jul 27, 2009 2:45 am

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

Postby Melloware » Fri Jul 31, 2009 7:30 am

DJGummikuh wrote:And for my post before that? The one with the code suggestions?


OK try the new build.

http://melloware.biz/download/warez/jintellitype-1.3.2-dist.zip

I modified your code slightly so let me know if it works. I used the following cleaner code...

Code: Select all
public static void setLibraryLocation(String libraryLocation) {
      final File dll = new File(libraryLocation);
      if (!dll.isAbsolute()) {
         JIntellitype.libraryLocation = dll.getAbsolutePath();
      } else {
         // absolute path, no further calculation needed
         JIntellitype.libraryLocation = libraryLocation;
      }
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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

Next

Return to JIntellitype

Who is online

Users browsing this forum: No registered users and 1 guest