aspose file tools*
The moose likes Beginning Java and the fly likes Shortcut to a .jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Shortcut to a .jar" Watch "Shortcut to a .jar" New topic
Author

Shortcut to a .jar

Jessid Leon Velez Gutierrez
Greenhorn

Joined: Dec 04, 2006
Posts: 22
Hello. I am writing a little program to create an installer of an application I wrote, and I want to create a shortcut in windows to access through the start menu. I know that it has to be possible from java, because programs like izpack create the shorcut i am trying to do.

Could someone, please help me or give me some advice???

Thanks a lot!!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
If the .jar is executable and has all its classpaths in the manifest file, and the file association with java/javaw is set up in the Windows registry, you can usually execute a .jar file on Windows by double-clicking it.
Jessid Leon Velez Gutierrez
Greenhorn

Joined: Dec 04, 2006
Posts: 22
Hello Campbell Ritchie. Thanks for answering. I had a little mistake writing my question, because what i want is to create the shortcut with the installer and I don't want the user to do the right click steps... just when the installer has finished, the user should be able to access my jar through the start menu.

Thanks again
[ July 25, 2008: Message edited by: Jessid Leon Velez Gutierrez ]
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3689
    
  16
A short cut is I believe just another file, so if you knew the format of this file you might be able to create one using Java. Without knowing the format you would probably need to use a Windows API to create it and that would require the use of JNI.
If you look at the Izpack website, you will see that all the Windows specific features (creating shortcuts, registry entries, ect) are optional features, which means they most likely supply an exe or dll that they access using JNI.


Joanne
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
the user should be able to access my jar through the start menu.


The contents of the Start|Programs menu on Windows XP comes from several folders.

One of them on my system is:
C:\Documents and Settings\Owner\Start Menu\Programs\
Other versions have different locations that may be pointed to by an Environment variable.

To allow a user to start your program from the Start|Programs menu, I guess you'd have to add a folder in the above path and create a shortcut in that folder.
Jessid Leon Velez Gutierrez
Greenhorn

Joined: Dec 04, 2006
Posts: 22
Hello Norm. Exactlry what you said about creating a shortcut in that folder is what i want to do, but with java....how to create a shortcut???

Or if exists a command to run from de command line, that would be another help, because i could create a batch file and execute it using java

Thanks a lot!
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 687
    
    1
how to create a shortcut???

Don't have a clue. It would depend on the OS.
Windows might have a utility to do it, or perhaps thru a JNI program or as someone suggested, look at an existing shortcut and create one on your own.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

Originally posted by Norm Radder:

Don't have a clue. It would depend on the OS.
Windows might have a utility to do it, or perhaps thru a JNI program or as someone suggested, look at an existing shortcut and create one on your own.

I've tried investigating the .lnk format once before but it's quite hard. I have written some JNI code though that can do it, but it's a bit complex. You have to work with C interfaces - and that's not as easy as Java interfaces.

The trick is to use IShellLink and IPersistFile; this link has a small example which I used to get my code running.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jessid Leon Velez Gutierrez
Greenhorn

Joined: Dec 04, 2006
Posts: 22
Hello Rob. Thanks for answering. You are right when you say that is not easy to write a .Ink file. I also found what each byte means, bun dont know how to create them. I havent seen the link you tolme, but i will let you know when i do it.

Again: thanks a lot

See you!
Jessid Leon Velez Gutierrez
Greenhorn

Joined: Dec 04, 2006
Posts: 22
Rob, npi with the link you suggested.
npi: ni puta idea


After a long time asking in irc channels, i had the good idea to ask in #C channel and they suggested to ask in #winapi channel... do not enter there. Not a pleasant experience...

jejeje
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shortcut to a .jar