Idov
Idov

Reputation: 5124

Starting a Java process from a C++ process

How can I start a Java application from within a C++ process?

I don't want to invoke just some parts of the Java application, as could be done with JNI, but actually run the whole Java application.

Upvotes: 3

Views: 362

Answers (3)

neo
neo

Reputation: 2471

would system("your java command") work?

Upvotes: 1

Rob H
Rob H

Reputation: 1716

Yes, you can follow the steps at this link: http://java.sun.com/docs/books/jni/html/invoke.html

Note that the sample invokes the "main" method of the loaded class so it would be just as if you did something like java -jar app.jar where the manifest in app jar specifies a main class that loads and starts the app.

Upvotes: 2

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81694

Sure, easily:

system("java ClassName");

You can certainly get fancier than that, adding environment variables for CLASSPATH or whatever else you need. The details of doing so may be moderately system dependent, however.

Upvotes: 1

Related Questions