In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use the Java extension mechanism to load all JAR packages, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
The Java extension mechanism is described in the Java tutorial as a "standard extensible way to enable all applications on the Java platform to use custom API". As described in understanding the extension mechanism for class loading, "the extension framework makes full use of the class loading proxy mechanism." This mechanism loads the extension class after the rt.jar boot (boot) class is loaded and before the class in the standard classpath is loaded.
The working mechanism of the extension directory is somewhat similar to that of classpath in class loading. For Java applications, classes contained in JAR files in all extension directories can be accessed. However, there will be some key differences. These differences are highlighted in the text below.
Typical application relevance of feature Classpath extension mechanism (optional package) scope
-classpath/-cp
Java.class.path
Class-Path of executable JAR Manifest
All possible JRE on the host
CLASSPATH environment variable
All JVM running on a specific JRE
Java.ext.dirs
JRE on various hosts
Solaris: / usr/jdk/packages/lib/ext
Linux: / usr/java/packages/lib/ext
Windows:% SystemRoot%\ Sun\ Java\ lib\ ext
How to specify .jar files
Explicitly specified by name (including .jar)
Use wildcards to match all .jar extensions
.class Files
Specify the .class file in the directory
All JAR files in the specified directory will be loaded (even if the extension is not .jar or there is no extension) class loading sequence boot and extension class loading after boot class loading, before class loading on classpath
One of the most important and noteworthy issues is that the extension mechanism finds all files in jar format, even if the file suffix is not .jar. This means that changing the suffix name of the jar file in classpath to avoid wildcard filtering does not work in an extended directory.
I will use some simple examples to show some of the differences mentioned above. The next two pieces of code are a simple HelloWorld class and a Main class in a main application. Main uses the HelloWorld class by calling the main method.
HelloWorld.java
Public class HelloWorld {@ Override public String toString () {return "Hello, World!";}}
Main.java
Import static java.lang.System.out; public class Main {public static void main (final String [] arguments) {out.println (new HelloWorld ());}}
To demonstrate the main differences between classpath and the extension mechanism, I will archive the compiled HelloWorld.class file into a jar package named HelloWorld.jar. And put it in a different directory than the compiled Main.class.
To demonstrate the use of traditional classpath, I put HelloWorld.jar in a directory called C:\ hello and use wildcards to access JAR for Main to use. The following two screenshots show this.
The screenshot above shows that when a class is in a JAR under the extension directory, the Java launcher does not even need to put the HelloWorld.class in the same directory or specify it in the classpath. This is often used to illustrate the advantages of using extension mechanisms. Because all programs running on this JRE (or possibly all applications on the host) can see the classes in the extension directory without being specified on the classpath.
Using the traditional classpath approach-instructing the application to load classes in JAR, the JAR file containing .class files must end with .jar. The following screenshot shows what happens when the HelloWorld.jar in the directory referenced by classpath is renamed to HelloWorld.backup.
* A screenshot shows that outdated HelloWorld classes in the extension directory take precedence over newly defined HelloWorld classes in the same directory. Even when I write the current directory into classpath, the old version of the class in the extension directory still takes precedence. The following figure also shows that the JAR file in the extension directory "hides" the updated JAR and the new methods of the classes in it. The JAR files in these extension directories don't even end in .jar.
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: 0
*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.