Java Compiling Java Program for Use Outside of Eclipse GUI - Nkk

  • Thread starter Thread starter nkk2008
  • Start date Start date
  • Tags Tags
    Java
AI Thread Summary
To run a Java program outside of Eclipse, compile the program and locate the .class files in the project's bin or specified classes directory. You can create a JAR file using the command line or Eclipse's export feature, which packages the necessary files for execution. To run the program, use the command "java -classpath . MyProgramName" or "java -classpath my.jar MyProgramName," substituting with the actual main class name. For GUI applications, a Runnable JAR File allows direct execution, while console applications may benefit from a CMD file to display output. This process simplifies running Java applications on other computers without the Eclipse environment.
nkk2008
Messages
32
Reaction score
0
I have a java program in Eclipse, and was wondering how to make it such that i can take a file or two onto another computer and run the program without the Eclipse GUI (i.e. as you would run/install a normal program). I am hopelessly lost from googling, as I understand nothing.

What is the best way to go about this?

Thanks,
Nkk
 
Technology news on Phys.org
Eclipse will stuff all the compiled .class files into some directory, I think [Project]/bin is the default but I always override it to be .../classes. You can copy those files to your target computer (or put them into a jar file, using the command line while in the classes directory: jar cvf my.jar *). To execute your program:
java -classpath . MyProgramName
or
java -classpath my.jar MyProgramName
where MyProgramName is the name of the java file which contains your main() method.
 
Note, that you can get Eclipse to help you pack all the needed files into a jar file by using right-clicking your Eclipse project and select Export / Java / JAR File or Runnable JAR File (use the build-in help on the resulting dialogs if you need more help on how to export).

If you program creates a GUI then the Runnable JAR File is useful as you can then simply run the file directly by running it from the Windows Explorer on any Windows where Java is installed. If you program only outputs to the console you probably want to make a small CMD file that contains the "java -jar jarfile.jar" command for you (so that running the CMD will make Windows open a console window and show your output).
 
Wow...I always wondered why Eclipse didn't have some easy way to create jar files...duh.
 
Thank you all. I will probably come back when I run into problems when I try this in a week (when the code is completely debugged), but for now I have some idea what I am doing.

Thanks,
Nkk
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top