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 mainly introduces "how to use Java's Classpath tools". In daily operation, I believe many people have doubts about how to use Java's Classpath tools. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to use Java's Classpath tools". Next, please follow the editor to study!
2. Problems that may arise
Whether they are willing to admit it or not, both beginners and experienced Java developers have been deceived by lengthy, complex classpath at some point (usually in the worst cases). The number of third-party and user-defined classes that applications rely on is growing, and classpath is becoming a place to pile up all possible directory and file names. At this point, it is no longer obvious which class the class loader loads first. This problem is particularly acute if the classpath contains duplicate class entries. As mentioned earlier, the class loader always loads the first class with the right name it finds in classpath, and in practice, it "hides" other classes with appropriate names but lower priority in classpath.
If you are not careful, you can easily fall into this classpath trap. After a long day's work, you finally add a directory to classpath to make your application use the best and latest classes, but at the same time, you forget: another version of this class is stored in another higher priority directory in classpath!
3. A simple classpath tool
Priority issues are inherent in the flat path declaration approach, but they are not unique to Java's classpath. To solve this problem, you only need to stand on the shoulder of the legendary software giant: the Unix operating system has a which command, specify a name in the command parameters, and which will display that name as the path name of the execution file when the command is executed. In fact, the which command is to analyze the PATH variable and find out where the command first appeared. This should also be a good tool for Java classpath management. Inspired by it, I started to design a Java tool, JWhich. This tool requires you to specify the name of a Java class, and then follow classpath's guidance to find out the absolute path to the location of the class that the class loader is about to load.
The following is an example of using JWhich. It shows the absolute pathname of the location where the Java class appears for the first time when the com.clarkware.ejb.ShoppingCartBean class is loaded by the com.clarkware.ejb.ShoppingCartBean class loader, and the search results show that the class is in a directory:
> java JWhich com.clarkware.ejb.ShoppingCartBean
Class 'com.clarkware.ejb.ShoppingCartBean 'found in
'/ home/mclark/classes/com/clarkware/ejb/ShoppingCartBean.class'
The following is a second example of using JWhich. It shows the absolute pathname of the location where the Java class first appears when the javax.servlet.http.HttpServlet class is loaded by the javax.servlet.http.HttpServlet class loader, and the search results show that the class is in an archive file:
> java JWhich javax.servlet.http.HttpServlet
Class 'javax.servlet.http.HttpServlet 'found in
'fileVouver prime homebank mclarkUniverse libUniverse servlet.jarlemagjavaxlemservletandhttpServlet.class 'HttpServlet.class
At this point, the study on "how to use Java's Classpath tools" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.