[英]Using Java from C++
As a C++ developer, I occasionally come across Java libraries like iText , Batik , JasperReports , and JFreeChart . 作为一名C ++开发人员,我偶尔会遇到像iText , Batik , JasperReports和JFreeChart这样的Java库。 In each case, equivalent cross-platform C++ libraries seem to be much less mature, much more expensive, or unavailable.
在每种情况下,等效的跨平台C ++库似乎都不太成熟,更昂贵或不可用。
Is it practical to use these Java libraries from my C++ app for reporting, charting, and similar? 使用我的C ++应用程序中的这些Java库进行报告,制图和类似工作是否切实可行? If so, what's the best approach to doing so?
如果是这样,这样做的最佳方法是什么?
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. 最简单的集成方法是老式的UNIX方法:启动一个小型Java程序,它可以完成您需要的任务并在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. 这在所有情况下都可能无法实现,但它绝对适用于PDF,SVG,报告和图表等用例,这些用例主要涉及生成单个文档以进行保存或显示。
Watch out for log4j, slf4j, JUL, etc. logging if you take this approach! 如果采用这种方法,请注意log4j,slf4j,JUL等日志记录! Anything that the Java program writes to standard out could corrupt the document you receive in the C++ program.
Java程序写入标准输出的任何内容都可能破坏您在C ++程序中收到的文档。 Disabling logging or using sockets may be better in that case.
在这种情况下,禁用日志记录或使用套接字可能会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.