The difference between the three kinds of library handling when eclipse exports a runnable jar package

When we package a runnable jar package in eclipse, there are three options in Library handing:
Write picture description here
So what is the difference between these three packaging methods of Runnable JAR file in eclipse?

The first Extract required libraries into generated JARmeans decompress the dependent jars and turn them into classes and throw them into the jars you generate; the
second Package required libraries into generated JARmeans don’t decompress the dependent jars and put them directly into the jars you generate; the
third Copy required libraries into a sub-folder next to the generated JARmeans to relied on Put the jar in the "xxx_lib" folder in the same level directory where you generated the jar.
Let's use an example to illustrate. Now I have a project here TestExport. The structure of this Java project is as follows.
Write picture description here
Now in the Test class, an external jar package written by myself is referenced Command.jar. Let's now use the above three methods to export to see how the effect is

Use the first method to export ( Extract required libraries into generated JAR)

Method of exporting Runable Jar file

Select the right project to be exported, the election Export.
Write picture description here
Select Java-->Runable JAR file-->Next
Write picture description here
the Launch configurationentry in the selection process, which is the class where the main method.
In the Export destinationSelect export position, click Browse...to select the location you want to export.
Then Library handingselect Extract required libraries into generated JARthe decompression dependent package mode in and
click to Finishexport
Write picture description here

After exporting, find the jar package and open
Write picture description here
it with a compression tool. You can see the contents inside.
Write picture description here
You can see that the first directory is the package directory of our project, and the contents are as follows.
Write picture description here
The second directory is the configuration file directory, this directory is bound to be there, don’t care about it.

The third directory is obtained by decompressing the dependency package Command.jar, and the contents are as follows.

Write picture description here

Use the second method Runable JAR file

The export method is similar to the previous one, so I won't talk about it again.
This time choose to export in the second way and save it to another directory, in order to avoid confusion.
Write picture description here

Then, find the jar and open it with a compression tool.
Write picture description here
The result of opening is as follows.
Write picture description here
You can see this way, right? The external dependency package Comman.jar is copied to the executable jar package Test.jar package we exported. Instead of extracting the Command.jar package to Test.jar as above.

Use the third method to export Runable JAR file

Still export to another directory in the same way,
Write picture description here
find the exported jar, and open the compression tool.
Write picture description here
You can see that there are now more folders in the same level directory of Test.jar Test_lib, Test_liband the external dependency package Command.jar
Write picture description here
and Test are stored in it . The jar is clean, only the files in the original project and the configuration file. The
Write picture description here
configuration file specifies the path of the dependency package Command.jar in the same directory.
Write picture description here
If we cut Test.jar to another place, then Test.jar , The dependency package in Test_lib will not be found, so it will run wrong.
For example, cut Test.jar to the upper-level directory and enter the java -jar Test.jarrunning program in cmd . At this time, the program will throw an exception:

Exception in thread "main" java.lang.NoClassDefFoundError: system/call/cmd/Command
  • 1

Write picture description here
The difference between these three is like this

Guess you like

Origin blog.csdn.net/xiaokanfuchen86/article/details/113919445