简体   繁体   中英

Running a Java Application from the Windows Context Menu

I would like to create a Java application that can be opened from the context menu of any given file or directory on the computer. I know how to add my program to the registry so that it appears when right-clicking on a file, but how can I receive the location of the directory/file from which my program was run in order to work with it inside the application?

Is there a way that I can receive it as an argument in the main?

First convert your jar to exe file. then you add to registry and whatever.. if you set whenever you open with right click on file ( you must set the file association, that is your application. Ex: Right click on your targeted file select open with and select your application ) your application main function receive the path in args[0]. that's all...

Add the context menu. Tell it to run CMD. Tell CMD to run the jar (and then close).

HKEY_CLASSES_ROOT\ * \shell\ClickMe\Command
default="cmd \\c java c:\myJar.jar \"%1\""

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