Could someone help me to develop a method to run any .jar file (with parameters) from in C# with XNA?

  • 3
    \$\begingroup\$ You may want to expand your search scope from XNA to C# in general - stackoverflow.com/questions/873809/… \$\endgroup\$ – SpartanDonut Jun 5 '12 at 15:23
  • 1
    \$\begingroup\$ @PatrickHughes Not really a duplicate of that question. That question is asking about compiling and using java code in C++. Not running already compiled code. \$\endgroup\$ – MichaelHouse Jun 5 '12 at 20:19
  • \$\begingroup\$ Rats, I misread. Don't close! \$\endgroup\$ – Patrick Hughes Jun 5 '12 at 22:02
  • \$\begingroup\$ Also, how would you even begin to integrate the Java code with C# functions? I mean I suppose it depends on your platform but I only see XNA as .NET and Java on its own in my small amount of experience of programming. More details needed, perhaps it's just best to develop these two separately. \$\endgroup\$ – A13X Jun 6 '12 at 2:37
  • 1
    \$\begingroup\$ -1; You really need to add some more details to this question. XNA doesn't have this capability at all, but you may still be able to do it using other C# facilities. The ones that are appropriate and the feasibility of your entire plan depend on where you intend to deploy your XNA app. This is almost certainly impossible on the Xbox, for example. Provide more information about what you're trying to actually do, maybe there is a better solution than running a JVM. \$\endgroup\$ – user1430 Jun 6 '12 at 15:15

Since you give absolutely no details as to why you want to do this or how it would be used. I'll just give you the most straightforward simple answer I can come up with.

Start Java as a process:

String pathToJava = @"c:\program files\java\bin\java.exe";//replace with automated method to find java on machine
String jarFile = "myjarfile.jar";
String parameters = "-p1 inputparam";
System.Diagnostics.Process.Start(pathToJava + " " + jarFile + " " + parameters);

You'd have to verify they have Java installed and that it's up-to-date. This is totally just a guess, since I don't use C# or XNA so I'm not sure if Process.Start is supported in XNA or not. But this is a start for you.

  • \$\begingroup\$ It is for Windows games and not for Windows Phone 7 or Xbox games. \$\endgroup\$ – lzcd Jun 6 '12 at 2:06
  • \$\begingroup\$ @lzcd I don't understand your comment. Do you know what Leoncio wants? I would hope it's not for Windows Phone 7 or Xbox, because I'm fairly sure neither has a Java virtual machine. \$\endgroup\$ – MichaelHouse Jun 6 '12 at 2:47
  • \$\begingroup\$ @Leoncio Thank you.1)Broadly,within XNA in WINDOWs,I want to expand my search scope from XNA to C# in general (for instance accessing a text file or running an exe file in DOS like: java nameProgram par1 par2 par3 par4->par4.txt (par are parammeters). \$\endgroup\$ – Leoncio Barros Jun 6 '12 at 13:31
  • \$\begingroup\$ @Leoncio A problem is that "Process.Start" does not seem to be supported in XNA, and corresponding code give errors. I supposed the kind of things I am requiring would be easy to implement in an advanced environmet as XNA! \$\endgroup\$ – Leoncio Barros Jun 6 '12 at 16:48
  • \$\begingroup\$ It seems that some people are able to do it. Perhaps you're doing something wrong? \$\endgroup\$ – MichaelHouse Jun 6 '12 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.