Sign in to follow this  

[java] Calling Java from C++?

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've finally figured out the mechanics of using the JNI, it's a shame that so few compilers available to me support it on both the Java and C++ ends. My problem now is to use C++ to call Java methods, particularly sending UDP packets and listening on certain ports. I'd code it directly in C++ myself if I hadn't had so much trouble and so little result that I've had. Anyway, several sources claim that the JNI CAN be used by the native "legacy" code to call Java methods. Except I've only found the following source go through it in any detail and to be honest I don't see how it works like that. It just looks like Yet Another Javaside JNI demo: http://www.javaworld.com/javaworld/javatips/jw-javatip17.html

Share this post


Link to post
Share on other sites
I still think you're trying to push a square peg into a round hole with this. Going through JNI just to handle UDP networking in Java is silly. You'll save yourself some work and maintenance headaches by knocking it up in C++ with the rest of your app. There are a plethora of resources on the net, and several good books out there that can teach you how to do it.

But if you're hellbent on doing this, take a look at this section of the Java tutorial (which, although I knew it existed, I found easily enough through Google). Pay particular attention to the link down the page a bit that says 'Interacting with Java from the Native Side". It shows you how to deal with Java Strings and arrays, access member variables, call methods, and more from the native code. If that doesn't solve your problem then I suggest you follow my advice above and forget this approach.

Share this post


Link to post
Share on other sites
You always get the good example of java usage from cpp side, when you install JDK(not JRE). Just look at %java_home%\src.zip[launcher\]
This dir has sourcecode of java.exe(java starter) with comments.
Actually it has a lot of comline analysing, but anyway it initializes JVM and starts app.

Share this post


Link to post
Share on other sites

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this