Executing Java Jar Files From VB

Posted on 2005-04-29
Last Modified: 2010-07-27
I am needing to execute an external Java Jar application through command line from my VB application.  I can create a .bat file to run the Jar file and this works fine when I execute it from command line or by double clicking it.  However I have tried using Shell, ShellExecute and when I try these with the .bat file I receive Java Errors.  Is there a way that I can either execute the .bat file or execute the Jar file directly from my VB.  I would prefer executing it directly because I would need to create the .bat file from my VB Application then execute it.

my current command line goes something like this

java -jar myfile.jar [Arguments]

Thank You
Question by:davidtrina
    LVL 18

    Expert Comment

    are the errors classpath errors? if so, try changing the current directory to the one your files are in (in the batch file).

    maybe also try,

    java -cp <path to jar> -jar myfile.jar
    LVL 7

    Accepted Solution

    Here is an example of how to run command line utils from VBscript without using batch files:  The example was in VBscript so you'll have to change Server.Create object so

    Project->References Windows Script Host Object Model

    Dim WshShell as WshShell
    set WshShell = new WshShell

    but the rest should be self explanatory.

    LVL 10

    Expert Comment

    Hi, davidtrina.

    Per the accepted answer in this EE post (,
    the following works for me:

    Just open Explorer, Tools/Folder Options/File Types, click "J" for Jar, make sure "Jar" is selected, click Advanced, make
    sure "open" is highlighted, and click "Edit".  Copy the path in the "Application used to perform action" box of the
    "Editing action for type: Executable Jar File" pop-up, and remove the code after "-jar", in my case, " %1".  Then create
    your Shell command with the path you just copied followed by the path to your Jar file:

         Shell "C:\Program Files\Java\j2sdk1.4.2_03\bin\javaw.exe -jar C:\BlackBerry.jar"
    LVL 1

    Author Comment

    Ok... I have been trying all the different answers, and I kept coming up with odd errors.  I have boiled the problem down, and would like to know if anybody knows what this is.

    In my application I have a Listbox and a Browse Button, the Browse Button uses Common Dialog Box to select some files to be processed through a java application.  I build the .bat file from the files in the listbox then save it and execute it.  Now here is the strange part.  If the last file that I selected (Through the Common Dialog Box) is on a MAPPED Network Drive I receive the same error as if I did not have the CD command in my .bat, but if the last file that I selected (Through the Common Dialog Box) is on my C Drive or if I type out the mapped drives real path i.e. \\ServerName\FolderName\FileName.txt it works fine.  The best I can figure is there is a conflict between Common Dialog with a Mapped drive and .bat files running.  It is frustrating to no end, and would appreciate any help anybody can offer.  

    Increasing the Point Value of this question accordingly.

    LVL 10

    Expert Comment

    Mapping can be presented in different ways, (e.g. \\, //\\, etc.)  If "\\ServerName\FolderName\FileName.txt " works, then maybe looking at what your Common Dialog has as the filename will help:

          Msgbox commondialog1.FileName

    Is there any difference between that value and the working string "\\ServerName\FolderName\FileName.txt "?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now