在 Xcode 4 中编译 Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15946163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compile Java in Xcode 4
提问by dustinboettcher
I know that this question has been floating around for ages now ...
我知道这个问题已经流传了很长时间了......
Java in Xcode 4.
Xcode 4 中的 Java。
I don't need any recommendations (Eclipse, Netbeans e.g.) I just want to compile some simple Java Code in "XCode4" (not 3). I managed to create a File and as expected the syntax and everything works but the Compiler due to the missing Scheme. I am kinda stuck at the executable.
我不需要任何建议(例如 Eclipse、Netbeans)我只想在“XCode4”(不是 3)中编译一些简单的 Java 代码。我设法创建了一个文件,正如预期的那样,语法和一切正常,但由于缺少 Scheme,编译器。我有点卡在可执行文件上。
My Question is:
我的问题是:
Is it possible to do that?
有可能这样做吗?
回答by Anoop Vaidya
Is it possible to do that?
有可能这样做吗?
YES this is possible.
是的,这是可能的。
1) File > New > New Project > Other > External Build System 2) Give it some name and save it somewhere. 3) File > New > New File > Other > Empty 4) Give it a Java-friendly name. In my example, use "HelloWorld.java" 5) Copy the contents below into the file and save. 6) File > New > New File > Other > Empty 7) Save as "Makefile". 8) Copy the contents below into the file and save. 9) The "Run" (>) button should at least compile your Java now.
Now it gets tricky. You don't have to do the next part. You could just open a Terminal to your project directory and run "java HelloWorld" if you want. I strongly suggest that. You can also just type "make" and use Xcode purely as a text editor.
现在它变得棘手。你不必做下一部分。如果需要,您可以只打开一个终端到您的项目目录并运行“java HelloWorld”。我强烈建议这样做。您也可以只输入“make”并将 Xcode 纯粹用作文本编辑器。
9) Project > Edit Scheme > Debug > Info 10) Executable > Other > type ^?g > type "/bin" > choose "sh" 11) Arguments 12) Set "Base Expansion on" whatever you named your target 13) Add an argument '-c "/usr/bin/java -classpath $(PROJECT_DIR) HelloWorld"' for this example. 14) Cross your fingers 15) Click the "Run" (>) button.
An Extract fromApple Support Community
Apple 支持社区的摘录