File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to create shortcut for a file using JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to create shortcut for a file using JAVA" Watch "How to create shortcut for a file using JAVA" New topic
Author

How to create shortcut for a file using JAVA

Shiva Kumar
Ranch Hand

Joined: Feb 09, 2001
Posts: 30
dear all,
i want to create an installation wizard for the appication that i have developed.my basic idea is to create a batch file to run my application and put in in a paricular location and a shortcut for the batch file and place it in desk top ,but i dont have an idea to create a shortcut for the batch file in run time using java code.could any body help me out in solving this problem.
thanks in advance
Shiva
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Any particular operating system in mind?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Mark Herschberg
Sheriff

Joined: Dec 04, 2000
Posts: 6037
On windows, I simply make a .bat file which runs the command line to run my java app, i.e.
java -classpath "..." -D<somekey/value> MyProgram
I have my installer include this file during installation.
It gets trickier if the JRE, classpath, and/or program can have a variable location. You need to use some combination of calls to the system, DOS commands (or cygwin commands if possible), and possible even MFC to figure out what to do. I would not try to do a shorcut in Java.
--Mark
Shiva Kumar
Ranch Hand

Joined: Feb 09, 2001
Posts: 30
thanks for reply
currently we need to create shortcut for Windows OS for the batch file that we create could you help me out.
Shiva
jasonkosowan
Greenhorn

Joined: Sep 07, 2001
Posts: 25
For this, you may want to open up a sample shortcut file in something like Notepad. It may be in plaintext and not some binary format, so you may be able to get away with creating the file using just the java.io.FileWriter.
Let me know if it works.
Shiva Kumar
Ranch Hand

Joined: Feb 09, 2001
Posts: 30

when i tried to open shortcut file in notepad or other utilities it only internally opens the original file for which shortcut is created.so i tried opening in dos prompt using 'type' command it showed the following:
L ☺�☻ └ F� P⌂;B╣╗☺ D♥☻n■└☺ ╡
how could we solve this.help me out
jasonkosowan
Greenhorn

Joined: Sep 07, 2001
Posts: 25
Oops, looks like shortcuts are binary encoded. Oh well, worth a try! Looks like you might have to invoke some JNI to get this to work if there is a command to create a shortcut. Would probably be your best bet now.
Originally posted by Shiva Kumar:

when i tried to open shortcut file in notepad or other utilities it only internally opens the original file for which shortcut is created.so i tried opening in dos prompt using 'type' command it showed the following:
L ☺�☻ └ F� P⌂;B╣╗☺ D♥☻n■└☺ ╡
how could we solve this.help me out

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create shortcut for a file using JAVA