In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the Classpath knowledge points of java". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "java Classpath knowledge points what" bar!
Java has the advantage that it is an automatic support network function of things, give a simple example to put
For example, there is an Application that uses java.lang.String(in fact, it is hard to imagine if there is a program that does not use it: ), and com.shinechina.MyClass (two versions I wrote myself).
Version 1:
package com.shinechina;
public class MyClass
{
public static void main(String args[])
{
String str = "Version 1: hello, welcome to chinaasp java technology";
System.out.println(str);
}
}
Version 2:
package com.shinechina;
public class MyClass
{
public static void main(String args[])
{
String str = "Version 2: hello, welcome to chinaasp java technology";
System.out.println(str);
}
}
Now I'm going to run it.
java com.shinechina.MyClass
now the question is coming
Maybe com.shinechina. Myclass has something like this on c: d: even on Aaron dude javabeans dude. It's cool stuff.
How does Java know where to look? What should he do?
Assuming version one at c: mylibcomshinechinaMyClass.java
Assuming version two at d: mylibcomshinechinaMyClass.java
Note: Do not forget to compile into class files, java files are not executable
cd c:mylibcomshinechina
javac *.java
cd d:mylibcomshinechina
javac *.java
Here we go:
He went to CLASSPATH of the machine first to find it
C:mylib;d:mylib;d:jdk1.2.2lib t.jar;
or unix system/home/local/:/usr/local/:/usr/local/jdk1.2.2/lib/rt.jar
OK, under c:mylib he found the com directory, there is play, and then look down and there is the shinechina directory, the directory found MyClass.class, Ok is him, as for d:mylib my version 2 MyClass he ignored, as for String is in the rt.jar compression package to talk about him later
And the result of that is
Version 1: hello, welcome to chinaasp java technology
If the path of disk d is before c: , the result of execution is
Version 2: hello, welcome to chinaasp java technology
And so on, only the first one found on the classpath will execute, and you have to control which one he executes so:
java -classpath d:mylib;%classpath% com.shinechina.MyClass
And the result of that is
Version 2: hello, welcome to chinaasp java technology
Execution in a development environment is like this, there is always a place to specify the classpath
Note that the development environment often does not read the system path, which is why things running outside slip into the development environment and die.
For example, jbuilder, jdeveloper from the menu project->project properties... -> paths Tags-> Add... -> Add a defined library dot ok or new-> enter name and classpath->ok
This item is added to classpath (see message view at runtime)
Another example is visualAge for java , click on the class you want to run-> right-click to select properties-> classpath label 1. -> Edit-> Select All, OK, all classes in the development environment can be found
2。-> Immediately calculate (only select the class you need, if there is a class such as class.forName explicitly loaded through the program, you need to manually enter it from the editor, and the development environment will help you calculate each ability. If there is no problem with memory, edit it directly-> Select All is more convenient)
3。If your class doesn't want to introduce a development environment, add an extra path to the dot, edit (the one below), I don't like that, so I won't go into detail
If you are a master, use jdk directly, then you have to trouble yourself to either add it to the system classpath ($CLASSPATH under unix), or explicitly indicate classpath at compile runtime.
Here's a beginner's mistake
Also the examples described in the previous section
Assuming version one at c: mylibcomshinechinaMyClass.java
compiled c: mylibcomshinechinaMyClass.class
How to specify classpath
Common problems
1。c:mylibcomshinechina
2。c:mylibcom
correct
1。c:mylib
2。c:mylib
At this point, I believe that everyone has a deeper understanding of "java Classpath knowledge points," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to 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: 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.