The JAVA and JAVAC commands are described in detail
- 2020-05-17 05:38:33
- OfStack
JAVA and JAVAC commands
The -classpath option on the javac and java command lines
This is a very basic question, but because most java programs are developed using existing IDE tools, very few people realize this point.
javac
-classpath, setting the path of the class to be searched, can be a directory, jar file, zip file (all class files inside), will overwrite all Settings inside CLASSPATH.
-sourcepath, set the path to search the java files required for compilation, which can be directories, jar files, zip files (all of which are java files).
So a full javac command line should look like this,
Assuming abc.java is in the path c:\src, you can compile in any directory by executing the following command.
javac -classpath c:\classes;c:\jar\abc.jar;c:\zip\abc.zip -sourcepath c:\source\project1\src;c:\source\project2 \lib\src.jar;c:\source\project3\lib\src.zip c:\src\abc.java
class file below c:\classed, class file inside c:\jar\ abc. jar, c:\zip\ abc. zip
c:\source\project1\src, c:\source\project2 \lib\ src. jar, c:\source\project3\lib\ src. zip,
Note: the source files in jar, zip will not be changed. The source files in the directory may be recompiled.
java
-classpath, set the path of the class to be searched, can be a directory, jar files, zip files (inside are all class files), will overwrite all CLASSPATH Settings.
Since the class to be executed is also part 1 of the class to be searched, 1 must put the class path in the -classpath setting as well.
In this case, when executing java in the path of the class to be executed, 1 must be marked (.) to indicate that this directory is also to be searched.
Suppose abc.class is in the path c:\src
The following command can be executed under any path
java -classpath c:\classes;c:\jar\abc.jar;c:\zip\abc.zip;c:\src abc
Question: if main.class belongs to c:\jar\ abc.jar and is in the package com.cnblogs.jeffchen, then java-classpath c:\classes; c: \ jar \ abc jar; c: \ zip \ abc zip; com. cnblogs. jeffchen. main can, but if classpath include multiple jar package? And what happens to other jar packages that have com.cnblogs.jeffchen? The mistake?
Under the windows,
The file path is separated by a backslash \
The delimiter of the class or java file list is a semicolon;
Under linux
The delimiter bit slash/for the file path
The delimiter of the class or java file list is a colon:
1 example of compile and run under linux
/usr/local/java/bin/javac -classpath /tmp/javatest/lib/mail-1.3.3.jar -d /tmp/javatest/bin/ /tmp/javatest/src/jp/co/realseed/Capability.java
/usr/local/java/bin/java -classpath /tmp/javatest/lib/mail-1.3.3.jar:/tmp/javatest/bin/ jp.co.realseed.Capability
Thank you for reading, I hope to help you, thank you for your support of this site!