2

I would like to make a GUI for a .jar file in Xcode.

I don't know much about coding, that's why I am asking. I have created this GUI1, but how do I get it to work with my .jar file? (In this case the minecraft_server.jar file for Mac.)

I am running commands in Terminal to start the server and I would like these commands to be applied when I press the Start Server button. (Like terminal were in the background of the app)

  1. The GUI

MineServer GUI

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
ifraaank
  • 122
  • 2
  • 13

1 Answers1

0

If the .jar file is a runnable jar from the command line i.e. if you are able to execute java -jar minecraft_server.jar something somethin, then you can simply create the GUI and issue java commands to the jar using `NSTask'. A good post on StakOverflow is Execute a terminal command from a Cocoa app

You may also need to monitor the process once running as well.

Community
  • 1
  • 1
Danish
  • 3,708
  • 5
  • 29
  • 48
  • I can't figure out what to do. Where should I use NSTask? In which file? :) Thanks for the fast reply. :) – ifraaank Nov 09 '11 at 14:55
  • I see, I am assuming you haven't started yet. Are you open to using any language? What I suggested was assuming that you're using Objective-C & Cocoa. If you haven't started, Java itself could be a good option as well. Which one do you want to use? – Danish Nov 09 '11 at 15:09
  • If it is possible, i would like to use Cocoa, just like the screenshot i posted. :) – ifraaank Nov 09 '11 at 15:15
  • I'm not a veteran of Cocoa development on the mac, but I guess you'll use the Cocoa application wizard to create a basic application. Then use the Interface Builder to design the gui and capture the click event of the "Start Server" button. In the handler for the button, you can write the code similar to the link I posted about " Execute a terminal command from a Cocoa app" – Danish Nov 09 '11 at 15:22
  • Thank you! I'll see what i can do. :) – ifraaank Nov 09 '11 at 15:24
  • I managed to get the button to start the jar file, but does it stay open? I can't find the server. :) Thanks. – ifraaank Nov 09 '11 at 15:51
  • Maybe you can use the `ps` command or the Activity Monitor application to see of the server is running. `NSTask` also has various methods to inspect the state of the task. I Googled for the reference and found it here - http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html – Danish Nov 09 '11 at 17:49
  • Since it's minecraft, you can monitor the input from the serve.log file, which gets updated as soon as something changes. I'm working on a similar project and I'd be very interested how you get the input working – alexyorke Jan 04 '12 at 11:24