Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create shortcut for a file using JAVA

 
Shiva Kumar
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any particular operating system in mind?
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic