0

Lets say that I built a GUI Application using NetBeans. To run this java application I need to open source code in IDE and then run. I know that I can also run through command prompt.

But how do I start the application independent of IDE. Isn't there some .exe file or something like that, which on double clicking directly runs the application?

If not, how do I generate such a file?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
AllLuckBased
  • 157
  • 1
  • 14
  • 1
    You can create the [jar](https://stackoverflow.com/questions/9681876/how-to-create-a-jar-file-in-netbeans) file and use it for running your application. – Praveen Aug 11 '18 at 21:41
  • 1
    Java programs compile to .jar files, which can be run like executable on machines that have the JRE installed on them. Depending on your IDE settings it may or may not keep the .jar file after you run your java program. I think in by default in NetBeans its located in an "out" folder in your project folder. – Misys Aug 11 '18 at 21:41
  • Can I take only this Executable JAR File on other machines and run it fine? – AllLuckBased Aug 11 '18 at 21:45
  • [Packing Programs in a JAR File](https://docs.oracle.com/javase/tutorial/deployment/jar/index.html) – MadProgrammer Aug 11 '18 at 23:52

3 Answers3

2

Here you can find how to create .jar in Netbeans: How to create a Jar file in Netbeans You can run the executable jar on every single computer, on one condition - the system have JRE installed. If you want to, you can also build the .jar using command line, to do that use the following command:

jar cf jar-file input-file(s)

Description from Oracle doc:

The options and arguments used in this command are:

The c option indicates that you want to create a JAR file. The f option indicates that you want the output to go to a file rather than to stdout. jar-file is the name that you want the resulting JAR file to have. You can use any filename for a JAR file. By convention, JAR filenames are given a .jar extension, though this is not required. The input-file(s) argument is a space-separated list of one or more files that you want to include in your JAR file. The input-file(s) argument can contain the wildcard * symbol. If any of the "input-files" are directories, the contents of those directories are added to the JAR archive recursively. The c and f options can appear in either order, but there must not be any space between them.

This command will generate a compressed JAR file and place it in the current directory. The command will also generate a default manifest file for the JAR archive.

lukbrt
  • 308
  • 3
  • 8
0

After you build your application look for a folder named "dist" in your project's folder. You should find there a file *.jar which can be run anywhere with double click.

Krystian G
  • 2,842
  • 3
  • 11
  • 25
0

STEPS TO FOLLOW:

  1. create a jar
  2. run the jar