开发者

How can I start a .NET application from Java on Linux, Mac and Windows?

I want to start a .NET application (compatible with Mono) from the context of a Java environment.

My guess would be that I'd have to somehow figure out if mono is installed, find the location and start that using the .NET application path as a parameter.

But what is a robust way to do it? Or is there a better way?

Perhaps I should clarify the context: the Java part is running as a plugin in an environment with limited interaction possible, so I would really prefer to find a way w开发者_如何学Goithout having to need a configuration file or an user-interface.


If you already have .net/mono already installed and you can double click on the exe file and it runs, then you could just use Desktop.open()

As easy as:

Desktop.getDesktop().open(file);

See here for more details: Using the Desktop API in Java SE 6 EDIT

I had to boot my Linux box where I have a mono application and this worked just great:

class Launch { 
   public static void main( String ... arg ) { 
      new ProcessBuilder("/usr/bin/myapp").start();
   }
}

Repeat, worked just great!


Interesting question! The answer is not that straightforward anyway

If you are running Linux

you definitely need Mono to run a CLR executable

If you are running Windows

you can run the CLR executable via shell OR use a local Mono installation (since Mono runs on Windows too), but there are very few reasons to run Mono on Windows

So, I think you should first detect the OS in Java (please don't ask me how to), and then if you are running Linux find Mono.

Mono's main executable is usually in /usr/bin, but is always in the $PATH so you can run mono Executable.exe from console. If you can't run such a command in Java, or Mono is not in path, then you need to run whereis mono to get the path to the executable.

No other ideas.


I don't know anything about .Net or Mono, but I would assume, it isn't much different to start a .Net application than regular one, or?

The class used to interface with the environment is java.lang.Runtime. It also allows you to execute commands. (.exec-methods)

In order to construct an appropriate command, the various functionality on java.lang.System will probably come in handy.

If this option is insufficient for the requirements of your particular situation, JNI might be your only option...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜