The difference between jar and runnable jar and the detailed process of exporting jar package

The jar file is the most common jar package, that is, the jar package under lib in our project, the jar cannot be run, that is, the class where the main function is located is not specified when the jar package is packaged (all classes that may be classified as jar packages are fundamentally There is no main function, just an ordinary class class, no main function), that is, there is no running entry (ie the main function). Therefore it cannot be run.


The Runnable jar file is an executable jar package, that is, the class where the main function is located is specified when the jar package is typed, so the jar can be run, starting from the main function of the specified class.



1.1 Export jar package

Detailed process:
(1). First, open the project in Eclipse, right-click the project, and select "Export";

(2). Select Java/JAR file (export runnable Java/Runnable JAR file), Next;

(3). In Select the resources to export, you can choose the project folder you want to include, and some unnecessary folders do not need to be put in, so as not to increase the space;

There are several options here:

    * Export generated class files and resources means to export only the generated .class files and other resource files
    * Export all output folders for checked projects means to export all folders of the checked projects
    * Export java source file and resouces means that the exported jar package will contain Your source code *.java, if you don't want to leak the source code, then don't choose this
    * Export refactorings for checked projects include some refactored information files as well

Select the path of the exported jar in Select the export destination, Next

(4.) On the next page, you can choose whether to export those *.class files that contain warnings or errors. Generally ignore him, Next

(5). In the next page, you can do some configuration for the project.

    * Generate the manifest file is the system to automatically generate the MANIFEST.MF file for us. If your project does not reference other class-paths, you can choose this item.
    * Use existing mainfest from workspace. This is our custom .MF file that can be selected, the format is as written above.
    * Seal content. To encapsulate the entire jar or the specified package packet
    * Main class. Here you can choose your program entry, and the jar packaged in the future will be the execution result of your entry class. (This is discussed in detail below)

Finally Finish, get it.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325815620&siteId=291194637
jar