5

Before someone shoots me down, I am aware of the Java to binary compilers and I'm not after one of those.

I also know there will be no perfect tool that converts everything without any problems. I am aware that missing Java libraries are a major problem; however my source doesn't make use of many Java libraries except for stuff like String and prints. I only want to the tool to create the classes that the Java source references. In the case of the String stuff I am happy to fill in the gaps or fix at a later stage. I just want the tool to do the boring bits so I don't have to do the translation manually.

In the case of required classes etc, I will manually fix those at a later stage but would appreciate a pointer to something that at the very least gets enough of the boring stuff done.

Once again I want the source translated and not a compiler to produce a binary. Basically I want to take some Java stuff and convert it to C++ for later use in other projects.

EDIT ADDITIONAL NOTES

Sorry if I was not clear in my previous parts of this question. I know that Java is very much different from C++. I have some Java code which is mostly filled with processing arrays and bits and has almost no object creation. In a sense it is very self-contained and has few calls to other classes. These classes seem to be prime candidates for conversion; the other stuff will have to be rewritten but at the least some parts are leveraged.

4

1 回答 1

13

j2c就是其中之一——它将 Java 源代码转换为其粗略的 C++ 等效代码。

显然,其他人提到了许多警告(垃圾收集、同步等),但它将提供一个很好的起点(并且它是开源的,因此您可以轻松地改进这一点=)。

根据您的代码库的大小,编写自己的代码库也可能有意义 - 一旦您有 Java AST 可以使用,编写一个并不是那么难,因为 Java 语法主要是 C++ 的一个子集,并且有许多库将为您解析 Java 代码(例如,j2c 使用 Eclipse 附带的库)。手动进行转换比为其编写工具更容易出错。

于 2012-04-15T05:07:45.910 回答