0

I run my java program in command linewith this statement

java myclass -a filetype.txt

But I want to run my program with right-click on a file with manipulating shell registry, but i don't what should write in shell default value

e.g for adding an option right-click to run with command prompt in windows, I set the default value with C:\Windows\System32\cmd.exe

but don't know how can run my java program with a simple right click.

1 Answer 1

1

If I understood you right, you want to right click on filetype.txt and run your java class on it?!

To achieve that you could do the following steps:

  • create a batch file (e.g. run.cmd) with the following content:

    java -cp C:\path\to\myclass myclass -a %1
    
  • create a registry key bellow HKEY_CLASSES_ROOT\*\shell (or HKEY_CLASSES_ROOT\.txt\shell if you want to apply your prog only to txt files)

  • name it what you want, and give it a value of your choice. This value will be what you see in your context menu
  • create another key bellow the recently created one and name it command
  • give it the value C:\path\to\run.cmd %1

that did the trick for me. If you don't like the additional *.cmd file, put

cmd /c java -cp C:\path\to\myclass myclass -a %1

as the value for the command key. And remember to use double quotes for paths that contain whitespaces.

Sign up to request clarification or add additional context in comments.

3 Comments

Maybe you can put it directly into command if you use the full java.exe path? Like C:\Program Files\Java\jre<something>\bin\java.exe?
I tried putting "%JAVA_HOME%\bin\java.exe" as command, but that raised an access denied error. Now I tried the absolute path of my jre and it worked. Maybe %JAVA_HOME% is not present in the registry.
Sometimes it's set as %JRE_HOME%, sometimes it just isn't set (by the installers, I mean).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.