2016-04-03 12 views
1

Bu konuda çok fazla araştırma yaptım ancak Java'da bulamadım. JAR'ı ilk kez eklentileri kullanmadan çalıştırırken masaüstünde bir kısayol oluşturmak istiyorum. İlk kez bir kısayol oluşturmak için yerel bir yol istiyorum.JAR'ı ilk kez çalıştırırken masaüstünde bir kısayol oluşturun.

Sadece ilk kez olup olmadığını bilmek için bir txt dosyası oluşturmak istiyorum, ancak zor kısayol oluşturur.

+0

http://stackoverflow.com/questions/343776/how-do-you-create-and-read-windows -shortcut-lnk-file-in-java yardımcı olabilir –

+0

Adım 1: Bunu http://stackoverflow.com/a/10226697/1897935 yapın. Adım 2: dosya var mı kontrol edin, başka oluşturun. –

+0

[http://stackoverflow.com/questions/1496343/how-to-create-shortcut-icon-for-java-program](http://stackoverflow.com/questions/1496343/how-to-create-shortcut -icon-for-java-program) – stark9000

cevap

1

Bir vb komut dosyası oluşturarak bunu ve java bunu yürütebilirsiniz:

import java.io.File; 

import java.io.FileWriter; 

import java.io.IOException; 



public class Shourtcut { 


    public static void main(String[] args) { 
     String path = System.getProperty("user.dir") + System.getProperty("file.separator") + "shourtcut.jar"; 
     path = '"' + path + '"'; 
     try { 
      File file = File.createTempFile("shortcut_geni", ".vbs"); 
      file.deleteOnExit(); 
      try (FileWriter fw = new java.io.FileWriter(file)) { 
       String vbs = "Set oWS = WScript.CreateObject(\"WScript.Shell\") \n" 
         + "sLinkFile = oWS.ExpandEnvironmentStrings(\"%HOMEDRIVE%%HOMEPATH%\\Desktop\\jar_file_name.lnk\")\n" 
         + "Set oLink = oWS.CreateShortcut(sLinkFile)\n " 
         + "oLink.TargetPath = oWS.ExpandEnvironmentStrings(" + path + ")\n" 
         + "oLink.Save \n"; 
       fw.write(vbs); 
      } 
      Process p = Runtime.getRuntime().exec("wscript " + file.getPath()); 
      p.waitFor(); 

     } catch (IOException | InterruptedException e) { 
      System.out.println("" + e); 
     } 

    } 

} 
+0

kodu eklemedi. Burada kısayol oluşturmak kavanoz net fasulye projesi için bir bağlantı: http://www.mediafire.com/download/5lhn3vrwe3144l8/shourtcut.7z – stark9000

İlgili konular