B4J Question Execute jar file inside b4j

Mashiane

Expert
Licensed User
Longtime User
Hi

How can I execute a jar file inside my b4j app. I am using the shell function to execute a jar file that gets generated by my app however its giving me an error that it cannot create the java virtual machine.
Below is my shell function which works for other operations.

B4X:
Sub RunWSH(sPath As String, sParameters As String)
    Dim shl As Shell
    Dim lstParams As List: lstParams.Initialize
    Try
        ' define the script to execute pass it the BAL and BIL files
        sPath = jMash.InQuotes(sPath)
        lstParams.Add(sParameters)
        shl.Initialize("shl", sPath, lstParams)
          shl.WorkingDirectory = ProjectPath
        shl.Run(-1)
    Catch
        Log(LastException.Message)
    End Try
End Sub

This is what I am passing to it to give those results
sPath
C:\Program Files (x86)\Java\jre1.8.0_77\bin\java.exe

sParameters
-jar C:\Users\Mash\Dropbox\MyApps\b4j\SOURCE~1\ABMaterial.Show\Objects\Projects\MyMaterial\Objects\MyMaterial.jar


The InQuotes sub just puts Quote inbetween the path.
Can someone please advise? Thanks
 

Attachments

  • error.png
    error.png
    14.2 KB · Views: 244

Harris

Expert
Licensed User
Longtime User
Try logging just before sh1.run. Then copy the log statement and run at command prompt to see if generates the same error.
 
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
May be path the to file is not validated. Try to run it from the command line.

Convert the path to canonical one. And change file separator to "/"
B4X:
   Dim fileO As JavaObject
   fileO.InitializeNewInstance("java.io.File", Array As Object(Path))
   Dim CanonicalPath as string = fileO.RunMethod("getCanonicalPath", Null)
   CanonicalPath = CanonicalPath.Replace("\","/")
 
Upvote 0
Top