Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Yair1978

macrumors newbie
Original poster
Jul 10, 2011
3
0
Hi,

I've downloaded Eclipse and I've done my first "hello world" program in Java. Now, I just really want to produce a runnable file that I can click on using finder or from the desktop without having to settle for running it from within Java or from the console. Also, I'd like it to run within the usual mac interface, perhaps producing a window in which it says its "hello world".

Can someone guide me through this? ;-)

(I've looked around for tutorials but only such that seem to assume a different version of Eclipse pointing to jar files that I can't find...)

/Yair
 
what you may be looking for is an applet or a desktop application to start. I use netbeans do i can't really guide you through it.

Applets are usually run in a web browser where a desktop application is your typical application for the desktop. the simpler out of both of these would be the applet, which i recommend starting with. you should try googleing "first java applet eclipse".

that should be a good start, with you just creating the hello world application you should experiment more with the console if you are a first time programmer and get familiar with loops and if-statements.
 
You can right click on the package name you can choose export then a dialog will pop up, choose runnable jar file, pick the package and a place to put it and it will create a jar file that you just have to run.

I'm not sure if you can just double click it though, I actually never tried it. I'm not sure how that would work anyway, as the output would go to a console, which you don't get when you double click the binary...

Sorry, hopefully that works for you... Or at least points you in the right direction.
 
I'd stick with command line utilities in Java before I'd even think about doing anything with a GUI.

When I had to create a GUI in my Java class, it was probably the biggest, most tedious pain in the ass ever. If you want to learn about GUI creation, look into Java Swing and Java AWT. Those are the tools we used in my class.

As for making a clickable application, you could use AppleScript to make an application ( not ideal but could be considered a work around ) with something like

do shell script "cd <where the file is> "
do shell script "javac -classpath . <nameOfFile>.java; java <nameOfCLass>"


Granted that's probably a horrendous AppleScript, something like that could work.
 
As for making a clickable application, you could use AppleScript to make an application ( not ideal but could be considered a work around ) with something like

do shell script "cd <where the file is> "
do shell script "javac -classpath . <nameOfFile>.java; java <nameOfCLass>"


Granted that's probably a horrendous AppleScript, something like that could work.

It's also unnecessary.

First, you don't need to compile the source every time.

Second, if a jar-file contains a manifest with a main-class, and that class presents a GUI, then double-clicking the jar-file will run the GUI on Mac OS X.

For more info, start with this:
http://developer.apple.com/library/...va14Development/00-Intro/JavaDevelopment.html

There's more available on developer.apple.com, but you'll have to search for it.

Another search term to google for:
jarbundler
 
It's also unnecessary.

First, you don't need to compile the source every time.

Second, if a jar-file contains a manifest with a main-class, and that class presents a GUI, then double-clicking the jar-file will run the GUI on Mac OS X.

That is a far more awesome idea than I had. That's pretty awesome, I didn't know that was possible. For class we had to use command line to launch, and since I was constantly changing I needed to recompile.


Do what chown33 said, his idea is far better than mine.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.