B4J Question Run jar exstras dinamical

Discussion in 'B4J Questions' started by ivanomonti, May 13, 2015.

  1. ivanomonti

    ivanomonti Well-Known Member Licensed User

    Hi,,,,,

    I need to launch the module jar from a secondary menu extra, I used this code, but without results


    Code:
    Sub bt_extras_Action
        
    ' path = C:\Users\MONIVA\odrive\Box\B4IOSP~1\PROJEC~1\ASSOCI~1\Objects\Moduli\test.jar
        Dim item As MenuItem = Sender
        
    Dim path  As String = File.Combine(File.DirApp, item.Tag)
        
    Dim sh As Shell
        sh.Initialize(
    "sh",path,Null)
        sh.Run(-
    1)
    End Sub
    Thank
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You need to run: java -jar <your jar file>

    You can find java path with:
    Code:
    javaExe = File.Combine(GetSystemProperty("java.home"""), "bin/java")
    You need to add -jar and <jar file> as the two arguments.
     
  3. ivanomonti

    ivanomonti Well-Known Member Licensed User

    Thank

    I used this code and it works, but now the problem and how to pass values to variables!!

    Code:
    Sub bt_extras_Action
        
    Dim item As MenuItem = Sender
        
    Dim path  As String = item.Tag
        
    Dim folder As String = File.DirApp & "\\Moduli"
        
    If File.Exists(folder,item.Tag) = True Then
            
    Dim sh As Shell
               sh.Initialize(
    "sh""java"Array As String("-jar"path))
               sh.WorkingDirectory =folder
              sh.Run(-
    1'set a timeout of 10 seconds
        Else
            
    Return
        
    End If
    End Sub
     
  4. Daestrum

    Daestrum Well-Known Member Licensed User

    Pass them after the jar file name, they will be treated as strings, then in the called jar they will be available in the args() array.

    ie, java -jar myJarFileToRunWithShell arg1 arg2 arg3

    Spaces separate the items so if you sent hello world, that is two arguments. To make it one argument enclose in double quotes "hello world".
     
  5. ivanomonti

    ivanomonti Well-Known Member Licensed User

    Thank 1000000000
     
  6. micro

    micro Well-Known Member Licensed User

    Hi to all
    I used this code but external jar not run:
    Code:
    Dim javaexe As String
    javaexe = 
    File.Combine(GetSystemProperty("java.home"""), "bin/java")
    sh.Initialize(
    "sh", javaexe & " -jar " & File.GetUri(File.DirApp, "Socketj.jar"), Null)
    sh.Run(-
    1)
    In sh_ProcessCompleted, Success return always False.
    where am I wrong?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    You are not using jShell correctly.
    You should add the arguments as an array:
    Code:
    sh.Initialize("sh", javaexe, array ("-jar"File.Combine(File.DirApp, "Socketj.jar"))) 'File.Combine instead of File.GetUri
     
  8. micro

    micro Well-Known Member Licensed User

    Thanks Erel, now work.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice