Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the setting method of classpath when the java Xbootclasspath parameter and jar parameter are running the application

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the setting method of classpath when java Xbootclasspath parameters and jar parameters are running applications". In daily operation, it is believed that many people have doubts about the setting methods of classpath when java Xbootclasspath parameters and jar parameters are running applications. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubt of "what is the setting method of classpath when java Xbootclasspath parameters and jar parameters are running the application"! Next, please follow the editor to study!

When you use java-jar yourJarExe.jar to run a packaged application, you will find how to set the-classpath parameter application can not find the corresponding third-party class, reported a ClassNotFound error. In fact, this is because when running with the-jar parameter, java VM shields all external classpath and takes only the internal class of its own yourJarExe.jar as the scope of the class.

Solution

A BootStrap class extension scheme

The Java command line provides an easy way to extend bootStrap-level class. -Xbootclasspath: the Java class search path that completely replaces the basic core. Not often, otherwise all Java core class-Xbootclasspath/a will be rewritten: suffix after the core class search path. Commonly used!-Xbootclasspath/p: prefix in front of the core class search path. It is not commonly used to avoid unnecessary conflicts.

The syntax is as follows: (the delimiter is similar to the classpath parameter, unix uses the: sign, windows uses the; number, here takes unix as an example) java-Xbootclasspath/a:/usrhome/thirdlib.jar:-jar yourJarExe.jar

Two extend class expansion schemes

Java exten class is stored in the {Java_home}\ jre\ lib\ ext directory. When Java is called, the search for the extended class path is automatic. It will always be searched. In this way, the solution is simple: copy all third-party jar packages to the ext directory.

Three User class expansion schemes

When executing the executable Jar package with-jar, JVM sets the directory where the Jar package is located to the codebase directory, where all class searches begin. So if you use other third-party jar packages, a more acceptable configurable solution is to use the Manifest extension mechanism of jar packages. The steps are as follows:

1. Copy the required third-party jar package in the same directory or subdirectory as the executable jar. For example, if the jar package is in / usrhome/yourJarExe.jar, then you can copy all jar packages to the / usrhome directory or / usrhome/lib and other similar subdirectories.

two。 Modify the Manifest file

Add the following line to the Manifest.mf file

Class-Path:classes12.jar lib/thirdlib.jar

Class-Path is the keyword on which the executable jar package runs. Note that Class-Path is only an acronym for your local machine's CLASSPATH environment variable, that is, using this prefix to look for third-party classes / libraries in all CLASSPATH directories on your jar package execution machine. You can't use Class-Path to load jar files located in your own jar package (or on the network). Because in theory, your jar distribution should not include other third-party libraries (but should remind users to get the appropriate supporting libraries by using instructions). If you have to package other third-party libraries (jar, zip, class, etc.) directly into your own jar package for distribution due to special needs, you must load these third-party libraries according to your intention by implementing a custom ClassLoader.

The first of the above three methods is recommended, which has good expansibility and the most convenient operation.

The security mechanism of Java varies with different JDK versions, which will affect many core CLASS, such as Thread, so many large-scale commercial software require the version of JDK to be very strict. Part of the reason is also here. This also requires the release of their own applications, regardless of size, to indicate the development and testing of the JDK version.

Add: jdk9 support-Xbootclasspath/a jdk8 and previous support for these three

At this point, the study of "what is the setting method of classpath when java Xbootclasspath parameters and jar parameters run the application" is over. I hope to be able to solve everyone's 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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report