• Post Reply Bookmark Topic Watch Topic
  • New Topic

Load jar from different locations  RSS feed

 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am creating a desktop shortcut for an exe file from java using jshortcut. The jshortcut jar file is in C:\Program Files\MyApp\lib. When I install my application I need it link with the jar automatically. I tried the below examples but those did not work ie, they did not load library.

DZone

Loading jars dynamically

How do I make my exe to link to the library during runtime? I am writing the program in java and then I am converting it to exe using launch4j.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about jshortcut or launch4j, but the usual approach to distributing an app would be to install all jar files with it, and have them be referenced from the app's manifest. Or use a shell script that runs the app and sets the classpath as appropriate. But I can't really tell what specific problem you're trying to address; "link with the jar automatically" doesn't mean anything to me (there is no linking in Java).
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

My problem is the jar file is in C:\Program Files\MyApp\lib folder. But my installer will be in some other drive. The installer is an jar converted to exe. If I run my installer say from D drive but the dependent jars are in C drive, there will be ClassNotFoundException right? I need to solve this problem. My requirement is that the installer should be a single exe file.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't the installer in control where to put all files? There should be no problem putting all files into the same directory, thereby obviating the need for classpaths that contain disk names or directories. If the installer can't even do, then it's severely underpowered, IMO, and you might be better off thinking of other approaches to distribution.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

You are right. The installer extracts all the files to the specified location(C:\Program Files\MyApp\lib). My question is how to use or load the specific jar for creating shortcut at the time of installation after extracting it to C drive? I need that jar to create shortcut else it will throw a ClassNotFoundException.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The shortcut should be of the main jar file (which contains the manifest pointing to all other jars), or it should be to a shell script which sets the classpath correctly. Either way, no pointing to any other directories is necessary. What am I missing?
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

The shortcut is a separate jar file. When I examined the manifest file of the installer jar, it has Class-Path: lib\jshortcut.jar. If I change it to C:Program Files\MyApp\lib\jshortcut.jar, it shows cannot load main class myapp.Myapp
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't sound like a smart thing to do on the installer's part. Why aren't you simply creating a standard Windows shortcut to the main jar file or a shell script? If install4j is worth anything, it should be able to do that. I generally have a low tolerance for tools that get in the way instead of making things easier.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf,

My client needs the final product in exe format, so I used Launch4j to convert jar to exe. Launch4j doesn't create shortcut, as far as I know. So I explored and got jshortcut. So what can I do now to achieve the desired result. In normal installations, shortcut is created at the end. I need my java app to go through such normal installation.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a proper installer like install4j or, since it's an .exe, the user can put it anywhere he wants, including the desktop.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!