Tool to convert Java source to C++ source [duplicate]
Asked Answered
T

1

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.

Tandi answered 12/4, 2012 at 1:36 Comment(5)
If you really want to access your java utilities from C++ then you could use JNI instead of porting them.Denmark
Possible answer from the duplicate: tangiblesoftwaresolutions.com/Product_Details/… - but tools comes with a lot of caveats, and is not free.Denmark
@jesse if im asking for a java -> c++ how can that be a duplicate of yor suggestion which goes the other way ?Tandi
@michael not quite, i wish to convert some java classes to c++ so i can reuse the logic they contain. The important part is SOME, i know it is not possible to convert Everything.Tandi
tangiblesoftwaresolutions.com/product_details/…Sidwell
E
13

j2c is one - it will convert Java source code into its rough C++ equivalent.

Obviously there are many caveats that others have mentioned (garbage collection, synchronization, etc) but it will provide a good starting point (and it's open source at that so you can easily improve that point =).

Depending on the size of your code base, it might also make sense to roll your own - writing one is not all that hard once you have a Java AST to work with given that the Java syntax is mostly a subset of C++, and there are many libraries which will parse Java code for you (j2c uses the one that comes with Eclipse for example). Doing a conversion by hand is a lot more error-prone than writing a tool for it.

Edgerton answered 15/4, 2012 at 5:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.