Results 1 to 5 of 5

Thread: How to run a jar file?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    75

    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.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    75

    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.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    75

    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
  •  



Click Here to Expand Forum to Full Width