Hi Dw

I would like you to help me here, i've googlished for this but it seems as if my problem is a bit complecated. I've created a program in java which has the '.jar' extention and then I created a program in VB.net which is an executor of the java program now the problem that I'm having now is that I want to put the java program inside the VB.net program so that when packing or exporting the program or the project the java program will be inside the vb application so that there will be only one file which will be '.exe' extention now the problem is putting this java file or should i say calling it something like

process.start("java" "-jar " & My.Resources.myjavafile.jar)

note that if I call the application in my Drive like drive D:\myjavafile\dist\myjavafile.jar it execute very well but if i try to put it inside the VB application program the system don't show it after i press the'.' after resource(s). Any help with instructions on how to do this will be apreciatable.

Thank you

If I'm not mistaken a '.jar' file is basically a text file. Renaming it with a '.txt' extension, will allow Visual Studio to load it as text. It's a simple matter from there to write it to disc, to run it, and delete it after you're done.

I think the '.jar' file is more like zip because you can also extract it to view some files inside, but I think changing an extention to '.txt' will help in loading it to VB because when I tried to load it in a '.jar' extention it said a dimension of byte can not be converted to byte so I think if I change the extention and when calling it call it as a '.jar' so it will change on runetime from '.txt' to '.jar' extention, when I've tried this I will then inform you

If text,System.IO.File.WriteAllText, doesn't work you can also do the same thing with bytes, System.IO.File.WriteAllBytes

Can you please give me a sample on how I should use that System.File.IO... Codes here is what I have so far: JavaProcess.StartInfo = New ProcessStartInfo("java", "-jar " & My.Resources.Myproject1). JavaProcess.Start(). Sorry for not formatting the codes I'm using a phone. Now with this codes the command window show and hide same time so I'm not sure if it do execute the jar file or it doesn't work because it hide before executing the file. So I don't know how I will be able to execute and see it while running.

Since text doesn't seem to work for you, you can add the file as a regular file. When you add it, change the filter to All Files. Once it's in your resources accessing and writing it to disc can be done this way:

IO.File.WriteAllBytes("Java1.jar", My.Resources.Java1)

This uses the default path so that when you run it you only need the file name. You'll need to decide if you want the .jar file written once and re-used, or written evry time the app starts then deleted.

To see if the file runs you can use the cmd console. put the file where it has a short path, like 'C:\' then if java is in your Path run 'java -jar C:\Java1.jar', if it isn't you may have to 'cd' to the folder holding the executable and run it from there.

Edited 3 Years Ago by tinstaafl

Did it run on you because here it doesn't I even put the full path for testing of the jre but still it doesn't and I tested if the file is recorgnised by changing the file I added a text file containg text for testing and I change the java.exe in the codes and replased it with a notepad.exe and othe other side I put the file name which is test1.txt and I debugged it aand it runned well but when I change to my project it doesn't run it I really don't know now what to do anymore.

Here's the code I used. One thing I noticed is that with 'UseShellExecute' set to True the window is open and active but doesn't stay on top.

    IO.File.WriteAllBytes("MySampleProject.jar", My.Resources.Java1)
    Dim proc As New Process
    proc.StartInfo = (New ProcessStartInfo("C:\Program Files (x86)\Java\jre7\bin\java.exe", " -jar MySampleProject.jar"))
    proc.StartInfo.UseShellExecute = False
    proc.Start()
    proc.WaitForExit()

This code assumes the .jar file is loaded as a resource of type All Files. I named it Java1 to prevent confusion between the resource and the file on the disk.

When you start a process like this everything has to be perfect because the process won't throw an exception it'll just end with an error code.

Edited 3 Years Ago by tinstaafl

Thank you so much it first didn't work then I created a new project then tested from it and it runned I think it was confused on the project that I was using because I've added and removed this jar file on it so I think it was confused or maybe it was the xml code that I deleted containing this jar file name after I deleted it from the folder and when I debugged it by that time it gave me an error that the file is missing but because I've removed the file manually I then deleted the line that was producing the error which was containing the file name, thank you again will mark this thread solved now thank you. ;-)

This question has already been answered. Start a new discussion instead.