Generally the IDE automates this for you, I use NetBeans and every time you build the project it generates the jar, which is in the project's dist folder. In the case of Eclipse I think he also does it somehow (I do not know). Now if you want to do this in CMD it is as follows:
1- Create a manifest.txt file in the package directory that contains your entire application with the following content (assuming your main class is in the app.main package and is named MainWindow):
Main-Class: app.main.MainWindow
Home
Name: app / main / MainWindow.class
Home
Java-Bean: true
- The first line 'Main-Class: ...' is where you define the package of your main class (class containing the main function), as if it were an 'app.main.Window' import. >
- The second line 'Name: ...' informs you the directory of your main class, from the directory of the manifest.txt file, if it is in the same directory as the main package, the first line will look like the second, The difference is that you use '/' instead of '.' and must specify the '.class' extension of the main class.
- The third line 'Java-Bean: true' tells you that you want to use the java bean option.
Open the CMD and navigate to the manifest.txt file directory, then type:
jar cfm ApplicationName.jar manifest.txt app
So you specify the name of your application, include the manifest file that makes some important specifications about your file (.jar), and defines what will be contained in (.jar), in this case the main package containing everything is the app package.
Your jar is ready!