开发者

calling a unix exectuable via a java enterprise application

开发者 https://www.devze.com 2023-02-10 13:59 出处:网络
c开发者_如何转开发an a java application call a unix executable written in c++? basically i have written code in unix in c++ and shared the executable with a couple of companies. All is well save for t

c开发者_如何转开发an a java application call a unix executable written in c++? basically i have written code in unix in c++ and shared the executable with a couple of companies. All is well save for this on e company that is using java under a linx platform. would it not be possible for them to just call my executable from their java app? of course i make sure my unix os matches their etc etc. but i don't want to redevelop my code using java for this. any solution to this problem?


Yes, it's possible. To execute a command:

String command = "./myscript";
Process process = Runtime.getRuntime().exec(command);

You can change the command to execute your C++ program.

See also here and here (the latter of which discusses Windows as well as *nix.)


Have a look at ProcessBuilder. I'm assuming your executable is a compiled command line application (and you're not out to call / integrate your C++ code from Java directly).


Java would still be using the operating system to run the native code. To run your program on Linux you need to compile a Linux binary.


Yes, you can. Take a look at the Runtime class in the Java api, you will found your answer there. But also, be aware of what J2EE Specifications are about doing these kinds of things.

Cheers.


As long as you can run the command without Java, you can use Runtime.getRuntime().exec(command); to launch it from a Java process.

0

精彩评论

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