• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3652
  • Last Modified:

Executing Java Jar Files From VB

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
0
davidtrina
Asked:
davidtrina
1 Solution
 
bobbit31Commented:
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
0
 
wesbirdCommented:
Here is an example of how to run command line utils from VBscript without using batch files:
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21099501.html.  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.

0
 
edwardiiiCommented:
Hi, davidtrina.

Per the accepted answer in this EE post (http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20549024.html?query=run+jar+file&topics=93),
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"
0
 
davidtrinaAuthor Commented:
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.

0
 
edwardiiiCommented:
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 "?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now