Jump to content
xisto Community
Sign in to follow this  
xenador

Java Run Without Command Line Or Jde new to java, is there a way to run code on a machine without the jde?

Recommended Posts

So I have learned a few basic concepts mostly dealing with algorithms and primatives, although we have now covered some useful things like polymorphism and inheritance...anyways, so I can do a lot with the code, and I was wanting to make a simple game and put it on another machine, but I have always had to compile the code via command prompt and then run it, is there a simple way to have my program run on any machine by doubleclick? (without the jde)

Share this post


Link to post
Share on other sites

You can make a executable jar file so that you can launch the application by double clicking the jar file. But you still need JRE (Java runtime environment) installed to execute jar files. Not only this...every java application needs JRE to run. Since, you're learning basics of java making a jar file looks some what difficult for you because you're likely to encounter many errors which you can't understand. Better stick to command line at present and once you master these basics you can try making jar files. :)

Share this post


Link to post
Share on other sites

It's quite simple. At the top level directory where you have you .class files (typically classes or bin diretory) create a file called run.bat (assuming you are using windows). Edit the file using Notepad and put the following in it:

java -cp . yourClass arg1 arg2

where yourClass is the class that runs you program - the one with the main function. arg1 and arg2 are two example arguments you want to pass to your main function (optional depending on your program)

Then just double click the run.bat file to run it. Copy this top level directory to another machine to run it from there

For more see

http://forums.xisto.com/no_longer_exists/

Good luck! And don't be daunted by all this - it will become very simple after a while

Share this post


Link to post
Share on other sites

hmm, i don't know what course you're into but here the most famous way of developing java apps is by using "eclipse" it is a java development platform like visual c/c++ and has many useful features, like build in compiler so you don't have to write code from the command line every time you want to compile your code it is as simple as a mouse click. Try googling it and come say do you like it.

Share this post


Link to post
Share on other sites

cool. So I have learned a lot more about what I am actually doing and we ended up using eclipse for the ide like yall mentioned. I finally got around to trying out the .bat file with a simple code and it kinda works... my Test.java file was as follows:public class Test{ public static void main(String[] Args){System.out.println("Hello World!"); }}no incoming args expected as you can see so my .bat file reads:java -cp . Testupon double click the dos window is displayed with hello world! but it is just for a fraction of a second. I assume this means that the program thinks it is done...and in this case it is, but I am trying to use the System.out.println to communicate with the user in the class that I am writing so I need the dos prompt to stay open...I checked the link and didnt note any commands to accomplish that. Any tips?

Share this post


Link to post
Share on other sites

I would begin using the javaswing class.That's the visual interfacefor java where you can set up widgets and textboxes and stuff. I think it's best to learn a language in notepad rather than using something likenetbeans or eclipse for java. For me,it just gave me a clearer understanding right off. That's the the thing about java.You have to declare an instance of your applicationin order to run it.That's a true class oriented language.

Share this post


Link to post
Share on other sites

no incoming args expected as you can see so my .bat file reads:java -cp . Test

upon double click the dos window is displayed with hello world! but it is just for a fraction of a second. I assume this means that the program thinks it is done...and in this case it is, but I am trying to use the System.out.println to communicate with the user in the class that I am writing so I need the dos prompt to stay open. Any tips?



In your .bat file, add another line "pause". This will keep the command-line window open till the user presses a key on the keyboard.

Alternatively, you can get the Java program to read, thus keeping the command-line window open till the user enters some data.

If you need more help, reply back and I'll send you an example.

Regards,
Nitin

Share this post


Link to post
Share on other sites

networker: yeah gui's are brand new to me, they refuse to teach us about them in school because its too language specific...anyways I found an addon called Jigloo and it is making learning to create them much easier.I do agree with you on the notepad approach for at first, (actually Notepad++ IMO is much better) but eclipse helps out with the auto-completes it does.Nitin: wow, works like a charm. Thank you very much. I have another question though...would you happen to know where to look to find out how to make the pathfile and the calling command not show? aka I dont care how the file got called I just want to see what is sent to System.out.

Share this post


Link to post
Share on other sites
batch filesJava Run Without Command Line Or Jde

"would you happen to know where to look to find out how to make the pathfile and the calling command not show? aka I don't care how the file got called I just want to see what is sent to System.Out."

xenador: If you want to get rid of the java call in your batch file, you can use @echo off to make the cmd prompt not repeat the contents of the batch file. For more info check out http://www.computerhope.com/batch.htm

-reply by Recent!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.