Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile Java in Xcode 4

I know that this question has been floating around for ages now ...

Java in Xcode 4.

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.

My Question is:

Is it possible to do that?

like image 421
dustinboettcher Avatar asked Apr 11 '13 10:04

dustinboettcher


People also ask

Is Xcode a good IDE for Java?

Available completely free of cost, Xcode is an IDE developed for macOS by Apple. This IDE comes with a multitude of software development tools for iOS, macOS, tvOS, and watchOS. This is certainly the top IDE for Java development on Apple.

How do I compile in Java?

Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\. Type 'javac MyFirstJavaProgram. java' and press enter to compile your code.

How do I compile a Java project from the command line?

Assume it's C:\. Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption: The path variable is set). Now, type ' java MyFirstJavaProgram ' to run your program.


1 Answers

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.

    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 from Apple Support Community

like image 193
Anoop Vaidya Avatar answered Oct 02 '22 03:10

Anoop Vaidya