使用J2Objc将Java代码转换为Objective-C

时间:2015-06-03 21:23:19

标签: java objective-c j2objc

我正在尝试使用J2Objc将Java中的Compression Scheme for Unicode实现转换为Objective-C。我已经成功下载并编译了J2Objc并在确保Java代码编译后运行命令./j2objec /SCSU/*.java。然而,我遇到了一大块错误,主要是说某些类,变量和函数是未定义的:

error: SCSU/Compress.java:41: SCSU cannot be resolved to a type
error: SCSU/Compress.java:63: The method getCurrentWindow() is undefined for the type Compress
error: SCSU/Compress.java:77: The method selectWindow(int) is undefined for the type Compress
error: SCSU/Compress.java:105: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:105: EndOfInputException cannot be resolved to a type
error: SCSU/Compress.java:105: IllegalInputException cannot be resolved to a type
error: SCSU/Compress.java:107: The method getCurrentWindow() is undefined for the type Compress
error: SCSU/Compress.java:126: IllegalInputException cannot be resolved to a type
error: SCSU/Compress.java:134: EndOfInputException cannot be resolved to a type
error: SCSU/Compress.java:143: IllegalInputException cannot be resolved to a type
error: SCSU/Compress.java:165: SQ0 cannot be resolved to a variable
error: SCSU/Compress.java:171: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:171: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:173: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:181: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:216: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:218: Debug cannot be resolved
error: SCSU/Compress.java:219: The method getCurrentWindow() is undefined for the type Compress
error: SCSU/Compress.java:224: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:228: SQ0 cannot be resolved to a variable    
error: SCSU/Compress.java:231: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:231: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:233: dynamicOffset cannot be resolved to a variable
error: SCSU/Compress.java:238: staticOffset cannot be resolved to a variable
error: SCSU/Compress.java:238: staticOffset cannot be resolved to a variable
error: SCSU/Compress.java:240: staticOffset cannot be resolved to a variable
error: SCSU/Compress.java:245: Assert cannot be resolved to a type
error: SCSU/Compress.java:249: Debug cannot be resolved
error: SCSU/Compress.java:266: EndOfOutputException cannot be resolved to a type
error: SCSU/Compress.java:279: The method isCompressible(char) is undefined for the type Compress

日志继续......为什么我会收到这样的错误,我该怎么做才能解决它们?

1 个答案:

答案 0 :(得分:1)

您需要指定源在-sourcepath中的目录(j2objc使用Eclipse编译器作为其前端,这是此要求的来源)。我将这些源文件复制到〜/ Downloads / unicode,并使用了以下命令:

$ j2objc -d build -sourcepath ~/Downloads/unicode ~/Downloads/unicode/*.java translating /Users/tball/Downloads/unicode/Assert.java translating /Users/tball/Downloads/unicode/Compress.java translating /Users/tball/Downloads/unicode/CompressMain.java translating /Users/tball/Downloads/unicode/Debug.java translating /Users/tball/Downloads/unicode/Display.java translating /Users/tball/Downloads/unicode/EndOfInputException.java translating /Users/tball/Downloads/unicode/EndOfOutputException.java translating /Users/tball/Downloads/unicode/Expand.java translating /Users/tball/Downloads/unicode/IllegalInputException.java error: /Users/tball/Downloads/unicode/SCSU.java:241: The method reset in type SCSU can only set one of public / protected / private

最后这是一个奇怪的错误,但是看看来源发现它确实是非法的Java:

SCSU.java:241: protected public void reset() { ...

修正(删除任一修饰符),你应该好好去。