Compiling Java Program for Use Outside of Eclipse GUI - Nkk

  • Context: Java 
  • Thread starter Thread starter nkk2008
  • Start date Start date
  • Tags Tags
    Java
Click For Summary

Discussion Overview

The discussion revolves around how to compile a Java program in Eclipse for execution outside of the Eclipse GUI, focusing on the process of creating a runnable JAR file and transferring necessary files to another computer. The scope includes practical application and technical explanation.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant expresses confusion about how to run a Java program outside of Eclipse and seeks guidance.
  • Another participant explains that Eclipse compiles .class files into a specific directory and suggests copying these files or creating a JAR file using the command line.
  • A different participant offers a method to export the project as a JAR file directly from Eclipse, highlighting the option for Runnable JAR Files for GUI applications.
  • One participant notes a realization about the lack of straightforward options in Eclipse for creating JAR files.
  • The original poster acknowledges the help received and indicates they may return with further questions after debugging their code.

Areas of Agreement / Disagreement

Participants generally agree on the methods for compiling and exporting Java programs from Eclipse, but there is no explicit consensus on the best approach, as different methods are suggested.

Contextual Notes

Some limitations include the assumption that the target computer has Java installed and the potential need for additional configuration depending on the program's requirements.

Who May Find This Useful

Individuals looking to compile Java programs for execution outside of an IDE, particularly those using Eclipse, may find this discussion beneficial.

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
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
6K
  • · Replies 13 ·
Replies
13
Views
2K