Reputation: 5073
I am developing a CAD software in which for my graphics part i am using opnegl & the kernel is being developed in c++. For the window interface i was adviced to use QT, but since my software is for commercial use i do not want to use QT, but rather use Java. My problem is, can i use jar exe in my c++ program (since my kernel is in C++ & the kernel controls the program)? If yes can anybody provide some simple example or some site. If no what is the other option?
I require the windows interface mainly for letting the user select the operations he wants to perform (create point, line, circle, etc), by providing some small icons on which the user can click. I also require the windows interface for pop-up window to show warnings, errors, take input arguments, etc.
Upvotes: 1
Views: 1662
Reputation: 3866
Whatever you do, do NOT use system(). //Here's why: http://www.cplusplus.com/forum/articles/11153/
Upvotes: 0
Reputation: 3663
You can embed the Java Virtual Machine directly into a C++ program. The JVM provides an API that allow to instantiate a VM in the same process space as your native program.
However, instead of embedding a JVM into your native application, I think it is a better idea to do the reverse: let the JVM call your native code.
Both require usage of the Java Native Interface (JNI), but in the first case there is a few additional steps to be done regarding native functions exposed to the VM. These additional requirements may be difficult to satisfy with large-scale native applications.
See the chapter 8.3 from the Java Native Interface Manual:
8.3 Registering Native Methods
[...] RegisterNatives is particularly useful when a native application embeds a virtual machine implementation and needs to link with a native method implementation defined in the native application. The virtual machine would not be able to find this native method implementation automatically because it only searches in native libraries, not the application itself.
Put it differently, all non dll_exported native methods must be manually registered to the VM. This is quite a heavyweight requirement.
Upvotes: 1
Reputation: 2787
You could use Qt even in comercial projects if you use their dll's without modification.
But you also could use JNI (Java native interface) to interface java with c++. Or you could use something like swig. Swig generates java classes from c++ clases. It simplifies the work of interfacing the two languages a lot.
It is maybe neccessary and different from what you wanted, that you need to start your application in Java. The Java then loads the c++ kernel via a dll and then calls the functions.
Upvotes: 2
Reputation: 29055
I don't know exactly how to run a JAR file via C++ (other then the obvious system()
or CreateProcess()
or fork()\exec()
calls to escape from C++ proper to the OS).
That said, you might consider having your application consist of multiple, independent processes that communicate via TCP or UDP sockets. Then each piece could be written in whatever language makes the most sense. For example, you could have the central core of the application (written in C++) set up a TCP server, then have "toolbar" apps (written in Java) send command packets to the core program via a dedicated socket connection. Come to think of it, UDP is probably better for that. Anyways, you get the point.
Also, not sure about your reasons for rejecting Qt--plenty of commercial apps have used it, and it is quite customizable (though I must confess I'm not a big fan of it myself, for other reasons).
Upvotes: 0