Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
3  
You may want to expand your search scope from XNA to C# in general - stackoverflow.com/questions/873809/… –  SpartanDonut Jun 5 '12 at 15:23
1  
@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. –  Byte56 Jun 5 '12 at 20:19
    
Rats, I misread. Don't close! –  Patrick Hughes Jun 5 '12 at 22:02
    
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. –  A13X Jun 6 '12 at 2:37
1  
-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. –  Josh Petrie Jun 6 '12 at 15:15

1 Answer 1

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.

share|improve this answer
    
It is for Windows games and not for Windows Phone 7 or Xbox games. –  lzcd Jun 6 '12 at 2:06
    
@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. –  Byte56 Jun 6 '12 at 2:47
    
@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). –  Leoncio Barros Jun 6 '12 at 13:31
    
@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! –  Leoncio Barros Jun 6 '12 at 16:48
    
It seems that some people are able to do it. Perhaps you're doing something wrong? –  Byte56 Jun 6 '12 at 17:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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