In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to solve the problem of ClassNotFoundException errors in running jar packages". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the ClassNotFoundException problem of running jar package.
The Java command runs jar to report an error
Run the jar command
Java-jar xxx.jar
Error report:
Caused by: java.lang.ClassNotFoundException:
Reason: the jar to be run is missing dependency packages
Execute the correct jar command:
Java-Xbootclasspath/a:/home/webuser/gogoal_platform/ggopenapi/lib/snakeyaml.jar-jar xxx.jar
Explanation:
-Xbootclasspath: completely replaces system Java classpath. Better not.
-Xbootclasspath/a: load after the system class is loaded. I usually use this.
-Xbootclasspath/p: load before the system class is loaded, pay attention to use, and conflict with the system class is not good.
Win32 java-Xbootclasspath/a: some.jar;some2.jar;-jar test.jarunix java-Xbootclasspath/a: some.jar:some2.jar:-jar test.jar
Each jar in the win32 system is separated by a semicolon and in the unix system by a colon
Mode two
AppClassloader to load
So you don't need the classpath parameter.
Let's add the following code to MANIFEST.MF:
Class-Path: lib/some.jar
Lib is a subdirectory in the same directory as test.jar, and the some.jar package to be referenced by test.jar is in it.
(I just started to understand that the lib folder was also packaged into test.jar, but it didn't succeed after practice. in fact, lib and test.jar are at the same directory and level.) then the test runs and everything is fine!
If there are multiple jar packages to reference:
Class-Path: lib/some.jar lib/some2.jar
Each individual jar is separated by a space. Be careful to use relative paths.
Another: if META-INF
Including the INDEX.LIST file under may invalidate the Class-Path configuration. INDEX.LIST is the index file generated by the Jar packaging tool when it is packaged, and deletion has no effect on the operation.
Jar package operation error: Invalid or corrupt jarfile
Execute:
Java-jar xxx.jar
When you run a jar package, you are prompted with an error:
Invalid or corrupt jarfile
The jar has been working normally before, but this time it just adds an image processing function and introduces opencv-2413.jar. Apart from the changes in the class file, the only modification is the MANIFEST.MF file. From an analytical point of view, the problem is likely to lie in this file, restore the file, sure enough, jar can at least start.
Isn't it just a new opencv added to the classpath in the MANIFEST.MF file, and why is that?
MANIFEST.MF is a very fragile file with strict format requirements. A space or a carriage return may invalidate the file, thus making the corresponding jar package illegal: Invalid or corrupt jarfile!
MANIFEST.MF format requirements
1. The contents of the file appear in the form of key-value key-value pairs, and key and value are separated by "English colon + space". Note: the space after the colon must be there; key must be written at the top, and there can be no space before it.
two。 The file cannot begin with a blank line, and the file always begins with the Manifest-Version attribute.
3. The file must end with a blank line. Note: the blank line cannot have any characters, including spaces.
4. Each line is up to 72 characters long, and if it exceeds it, a continuation is used, and the newline must begin with a space.
5. For paths that exist in the Class-Path attribute, separate directories with "/", regardless of the platform; multiple jar package references are used to separate spaces.
There are also questions about the saying that each line of an MANIFEST.MF file cannot exceed 72 characters. Because many lines of the Class-Path attribute in my MANIFEST.MF file are more than 72 characters long, they don't actually cause an exception.
The reason why my jar package reported an error is that it violates section 3 above. Although the file ends with a blank line, the blank line hides a space, that is, line 14 in the figure above contains a space.
At this point, I believe you have a deeper understanding of "how to solve the problem of ClassNotFoundException errors in running jar packages". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 261
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.