Everyone knows that a Java application project can be packaged into a jar, and of course you have to specify a main class with a main function as the program entry for your jar package. The specific method is to modify the Manifest.mf file in the Meta-inf of the jar package. For example, there is a jar bag called Test.jar, which has a main class:test.someClassName with a main function. We just add the following sentence in the MANIFEST.MF: Main-class:test.someclassname Then we can enter Java-jar Test.jar in the console to run this jar. But our project needs to refer to other third party jar packages, and in eclipse we refer to this package called Some.jar in the form of a project jar package, which was placed in the Lib subdirectory of the project, and the last project was packaged with the Some.jar, but with Java- The jar was unable to find the class exception when executing this test.jar because the jar reference does not have a jar package that is placed inside itself. So what to do. The way it is added to the classpath at run time is not OK. is to add the Classpath parameter while running the jar: Java-classpath Some.jar-jar Test.jar This way should be able to solve the problem, try, or not. Check the data, the original use of the Java-jar command to run the jar package when the classpath parameters will be invalidated, so this way is not. So how do you refer to the other jar packs, the answer is in the MANIFEST.MF file under this directory Meta-inf. The information that the jar package references other jar packages must be declared in this file. We add the following code to the MANIFEST.MF: Class-path:lib/some.jar Lib is a subdirectory of the same directory as Test.jar, Test.jar the Some.jar package to be referenced here. Then the test runs and everything works. If you have multiple jar packages that need to be referenced: Class-path:lib/some.jar Lib/some2.jar Each individual jar can be separated by a space. Summary: Anyway, just find a way to import the jar that needs to be referenced before executing Test.jar classpath. You can even put all the packages you need to refer to the Jre/lib/ext directory so that the JVM is loaded as soon as it starts. |