简体   繁体   English

将 Java jar 文件转换为 cpp

[英]Convert Java jar file in to cpp

I have a java code and created a jar file.我有一个 java 代码并创建了一个 jar 文件。 I need to create an Qt application.我需要创建一个 Qt 应用程序。 Can I use this code in that application?我可以在该应用程序中使用此代码吗? Please help me how can i use that jar file.请帮助我如何使用该 jar 文件。

Thanks, Nagaraju.谢谢,长良州。

You could take a look at the capabilities of GCC/GCJ (see http://gcc.gnu.org/ ).您可以查看 GCC/GCJ 的功能(请参阅http://gcc.gnu.org/ )。 IF it's a good idea is a whole other story, and depends on what you have, and what you're trying to accomplish.如果这是一个好主意,那就是另外一回事了,这取决于你拥有什么,以及你想要完成什么。 It should be doable to link SO's created with GCJ in QT applications, but I seriously wonder if you are not better off using either C++ or Java, but not mixing them在 QT 应用程序中链接与 GCJ 创建的 SO 应该是可行的,但我很想知道你是否最好使用 C++ 或 ZD52387880E1EA22817A72D3759213819,但不要混合它们

If your Java code takes input from stdin or some file and writes output to stdout or some file, then the easiest way is to fork java to run that jar, and parse the output in your Qt code. If your Java code takes input from stdin or some file and writes output to stdout or some file, then the easiest way is to fork java to run that jar, and parse the output in your Qt code.

Things other than that, you'll need to be a bit specific.除此之外的事情,你需要有点具体。 Something like "my Java code does painting the screen".像“我的 Java 代码确实绘制屏幕”之类的东西。

My advice is to use SWT or Swing.我的建议是使用 SWT 或 Swing。

You can use gcj gcj to compile the java code to library and simply call the functions of the java code from your C code.您可以使用 gcj gcj将 java 代码编译到库中,然后从您的 C 代码中简单地调用 java 代码的功能。

Yes, you can use your jar file in your Qt application.是的,您可以在 Qt 应用程序中使用 jar 文件。 I've done exactly this myself.我自己就是这样做的。

One way is to use the JNI Invocation API .一种方法是使用JNI 调用 API This is part of the Java Native Interface (JNI) , which makes it feasible but not pleasant to access Java APIs from C++.这是Java 本地接口 (JNI)的一部分,这使得从 C++ 访问 Java API 变得可行但不愉快。

A much more pleasant approach is to use CodeMesh JunC++ion , which wraps the Java APIs in C++ classes.一个更令人愉快的方法是使用CodeMesh JunC++ion ,它将 Java API 包装在 C++ 类中。 This is a great product, if you can afford it.这是一个很棒的产品,如果你能负担得起的话。

If you have very little Java code, it may be easier to port it to C++.如果您的 Java 代码很少,将其移植到 C++ 可能会更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM