简体   繁体   中英

Drag&Drop file to jar file (in Windows Explorer)

I have written a Java application, that analyzes some data from within a zip file.

I can pass the filename as command line argument to the application (java -jar myapp.jar fileToAnalyze.zip) and it does what it is supposed to do.

Unfortunately it is somehow complicated to call the application via command line. I would like to simply drag the ZIP file to the jar and let it start. I have absolutely no idea how to do this. Could you please give some hints?

Thanks in advance.

It seems that windows doesn't allow file drops on jar files. But short of finding a solution for that you could instantiate a JFrame when you run your jar file and make it listen for dropped zip files on that instead.

An example of that can be found here .

It still (10/2021) seems that Windows does not allow this.

What you can do:

  • create a batch file with the java call to your program. This will open a command line window along with your program and might seem ugly.
  • create a desktop link to your java.exe (or javaw.exe). In the properties of the link, add "-jar YourJarFile.jar" as command line arguments to the link target.

In both cases, Windows will send the dropped file to your program as command line arguments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM