4

As a C++ developer, I occasionally come across Java libraries like iText, Batik, JasperReports, and JFreeChart. In each case, equivalent cross-platform C++ libraries seem to be much less mature, much more expensive, or unavailable.

Is it practical to use these Java libraries from my C++ app for reporting, charting, and similar? If so, what's the best approach to doing so?

  • Use JNI to embed a JVM within my application?
  • Use GCJ to compile the Java libraries to native code?
  • Some other integration method that I'm not aware of?
  • Give up, since calling a Java library from C++ would be too hard to be practical, and instead invest my efforts in finding C++ libraries?
2
  • 1
    Add writing the GUI code in Java and running that as main calling C++ libraries via JNI Commented Sep 30, 2010 at 12:59
  • 2
    Do be careful with this - When you start bringing more tools in by grabbing an extra language and execution environment, you end up making the code a LOT harder for the next guy to understand. Having been the next guy, I can tell you that there's a lot to be said for not being too clever. Commented Sep 30, 2010 at 13:19

1 Answer 1

3

The least complicated method of integration is the old-school UNIX approach: launch a small Java program that does the task you need and communicate with it on STDIN/STDOUT.

This may not be possible in all cases, but it definitely is for use cases like PDF, SVG, reporting and charting which largely involve generating single documents for saving or display.

Watch out for log4j, slf4j, JUL, etc. logging if you take this approach! Anything that the Java program writes to standard out could corrupt the document you receive in the C++ program. Disabling logging or using sockets may be better in that case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.