javaobjective-cj2objc

How to translate an entire folder or package from Java to Objective-C?


I've used an older version of Google's Java to Objective-C (J2ObjC) converter previously (i.e. version 0.5.2) and it was straightforward to translate an entire folder of Java files to their equivalent Objective-C files (and to preserve the directory structure in doing so). I just had to run the following shell executable:

$ ./run.sh —-preservedirs <path to input folder>

I've just downloaded the latest version of J2ObjC (i.e. version 0.9.1) and it's not clear from the Getting Started page or elsewhere how I can translate an entire folder of Java files rather than just a single Java file using the j2obc executable. The only example provided in the Getting Started page is to translate a single Java file which has no dependencies or imports elsewhere as follows:

$ ./j2objc Hello.java

Can anyone provide me with an example of how to translate an entire package assuming I have a folder named input which contains my com package which contains all of the sub-packages and Java files that I want to translate?


Solution

  • If there is no better way built into run.sh, you could use find's -exec flag:

    find <path to input folder> -type f -exec --preservedirs ./run.sh {} \;
    

    Or, you could use xargs to do multiple files at the same type:

    find <path to input folder> -type f | xargs ./run.sh --preservedirs
    

    (You might also need to add -name "*.java" to the find arguments if there are non-Java files in your directories).