-
Jun 18th, 2021, 12:07 PM
#1
Thread Starter
Lively Member
How to run a jar file?
I am trying to run a jar file with a target using: Shell("java - jar {path1}File.jar {path2}TargetFile")
From a command prompt, when I run {path1}File.jar {path2}TargetFile
it works. However in Visual Basic, the statement Shell("{path1}File.jar {path2}TargetFile")
does not, presumably because I need to specify how to open File.jar.
However running java - jar {path1}File.jar {path2}TargetFile
either from a command prompt or using the Shell statement doesn't work..
What do I need to specify in my Shell statement to run the jar file with its target file?
Last edited by coffent; Jun 18th, 2021 at 12:31 PM.
-
Jun 18th, 2021, 12:54 PM
#2
Re: How to run a jar file?
Don't use the Shell command... use the Process object instead (I think that's the right class) ... give it the java as the command line and then the rest as the arguments (a separate property) ... then use the .Start (or it might .Run, I forget) to run it.
OK. so pass it "java" in the constructor, then the rest as .Arguments:
Code:
Dim startInfo As New ProcessStartInfo("java")
startInfo.Arguments = "-jar {path1}File.jar {path2}TargetFile"
Process.Start(startInfo)
Also there shouldn't be a space between the "-" and "jar"
More info:
https://docs.microsoft.com/en-us/dot...s?view=net-5.0
-tg
-
Jun 18th, 2021, 01:52 PM
#3
Thread Starter
Lively Member
Re: How to run a jar file?
Thanks - that fixed it! The only problem was the space between "-" and "jar". The Shell statement now works, though I'm wondering if there is some advantage in using the Process.Start command instead.
-
Jun 18th, 2021, 02:25 PM
#4
Re: How to run a jar file?
It's cleaner... it's specifically what it's designed for. It's also going to be able to handle things like quoted strings in the arguments better. You can also control if the window is shown, minimized, maximized, etc. You can also route the output (if it's a console application) and reroute the input as well. It also gives you a bit more control over the life of the process and knowing when it quits. Using shell is kinda like writng a message on a rock and throwing it over the wall and you hope it gets to your intended audience. Using the Process class gives you a chance to tie some twine to that rock before tossing it over, so you can control it a bit.
-tg
-
Jun 18th, 2021, 09:09 PM
#5
Thread Starter
Lively Member
Re: How to run a jar file?
Thanks for the info. I'll use that instead.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|