javac command Description
root@k8smaster01 json]# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user path to class files and annotation processors # specify compiled java source files need to rely on the .class file can be a directory, jar files, zip files (which are the class file)
-sourcepath <path > specify where to find input source files # path at compile source files need to rely java java file, can be a directory, jar file, zip file (which are the java files)
-bootclasspath <path> Override LOCATION class of files on Bootstrap
- extdirs <dirs> Override LOCATION Installed Extensions of
-endorseddirs <dirs> Override LOCATION path of Standards endorsed
-proc:. {none, only} Whether Annotation Control Processing and / or Compilation IS DONE
-processor <Class1> [, <Class2>, <class3> ...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files #指定生成的class的位置,会根据包名递归生成
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files #指定源文件使用的字符编码
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version # version of the particular virtual machine to generate class files
-profile <Profile> IS Used Available the Check that the API specified in Profile The
-version Version Information
-help A Synopsis of the Print Options Standard
-Akey [= value] to the Options Annotation Processors Pass to
the -X-A Synopsis of the Print Options nonstandard By
-J & lt <In Flag> Pass <In Flag> The Runtime System Directly to
-Werror the Terminate Compilation Represents warnings Occur IF
@ <filename> Options and of the filenames from the Read File @ one or more files on the source file list
[root @ k8smaster01 json] #
Case
1) java file compiled simple single free package of
[root @ k8smaster01 daima] # mkdir simpledemo # create the directory
[root @ k8smaster01 daima] # cd simpledemo /
[root @ k8smaster01 simpledemo] # pwd
/ the Data / the Java / daima / simpledemo
[root k8smaster01 simpledemo @] # vi editor Test.java # Test.java file, print a line of text
[root @ k8smaster01 simpledemo] # More Test.java
public class {the Test
static void main public (String [] args) {
System.out.println ( "Simple javac Demo");
}
}
[@ k8smaster01 simpledemo the root] # . # -d javac Test.java use javac compiler, class stored in the current directory
[@ k8smaster01 the root simpledemo] LS # -lrt
Total. 8
-rw-R & lt - r-- 1 16-Mar. 1 the root. 3 23:39 Test.java the root
-rw-R & lt - r--. 3. 1 the root 23 is the root-Mar 419: Test.class 40
[root @ k8smaster01 simpledemo] # the Java implementation of the Test # class file, normal printing javac simple demo data
javac simple demo
[root @ k8smaster01 simpledemo] #
2) the package has a simple single file compiles java
[root @ k8smaster01 simpledemo] # mkdir -p the src / COM / Test # New Directory
[root @ k8smaster01 simpledemo] # previous mv Test.java src / com / test / # Copy Test the java file
[root @ k8smaster01 simpledemo] # vi src / COM / the Test / Test.java # edit java files, add Package Penalty for
[root @ k8smaster01 simpledemo] # More src / COM / the Test / Test.java
Package Penalty for com.test;
public class Test {
public static void main(String[] args) {
System.out.println("javac simple demo");
}
}
[root@k8smaster01 simpledemo]# tree /data/java/daima/simpledemo/ #目录结构
/data/java/daima/simpledemo/
└── src
└── com
└── test
└── Test.java
Directories 3, 1 File
[root @ k8smaster01 simpledemo] # after the mkdir clazz # clazz new directory to store compiled class files
[root @ k8smaster01 simpledemo] # LS -lrt
Total 0
drwxr-XR-3 root root the X-16 Mar 23 3: the src 43 is
drwxr the root-XR-2 X-Mar. 3 23:46 clazz the root. 6
[root @ k8smaster01 simpledemo] # javac the src / COM / Test / Test.java compiled using javac -d ./clazz/ #
[root @ k8smaster01 simpledemo] # Tree / Data / Java / Daima / simpledemo directory structure / # compiler
/ Data / Java / Daima / simpledemo /
├── clazz
│ └── COM
│ └── Test
│ └── Test.class
└── src
└── COM
└── the Test
└── Test.java
Directories 6, 2 Files
[root @ k8smaster01 simpledemo] # the Java -cp clazz / com.test.Test # run the compiled file, the Simple Demo normal print javac
javac the Simple Demo
[root @ k8smaster01 simpledemo] #
Java files compiled 3) of the batch (relates dependencies)
[the root @ k8smaster01 the Test] # Tree / Data / java / Daima / code structure the Test # Engineering
/ Data / java / Daima / the Test
├── clazz
├── config
lib ├──
│ └── GSON-2.3.jar
└── the src
└── COM
├── Data
│ └── ParaMap.java
└── JSON
└── Test.java
7 directories, 3 files
[root@k8smaster01 daima]# more src/com/data/ParaMap.java
package com.data;
import java.util.HashMap;
import java.util.Map;
public class ParaMap {
public static Map<String,String> getMap(){
Map<String,String> sysParams = new HashMap<String,String>();
sysParams.put("localForceNewThread", "true");
sysParams.put("uuid", "28bcf60840f8416e8ea55ffe970c1623");
sysParams.put("log", "348a8a27e315e5a26c68a002.348a8a27e315e5a26c68a003.0");
return sysParams;
}
}
[root@k8smaster01 daima]# more src/com/json/Test.java
package com.json;
import java.util.Map;
import com.data.ParaMap;
import com.google.gson.Gson;
public class Test {
public static void main(String[] args) {
Gson gson = new Gson();
Map<String, String> sysParams = ParaMap.getMap();
String json=gson.toJson(sysParams);
System.out.println(json);
}
}
[root @ k8smaster01 daima] #
[root @ k8smaster01 daima] # More javac.sh # compiler script file compiled on clazz the
#! / bin / bash
PROCESS_NAME=test_javac
BASE_APP_HOME="/data/java/daima/Test"
jars=`ls ${BASE_APP_HOME}/lib`
for jar in $jars
do
CLASSPATH=${BASE_APP_HOME}/lib/$jar:$CLASSPATH
done
CLASSPATH="${BASE_APP_HOME}/config:${CLASSPATH}"
export CLASSPATH
echo "CLASSPATH=${CLASSPATH}"
find ${BASE_APP_HOME} -name "*.java" > ${BASE_APP_HOME}/sources.txt
sourcesclazz=`cat ${BASE_APP_HOME}/sources.txt`
echo "${sourcesclazz}"
javac -encoding UTF-8 -cp ${CLASSPATH} -d ${BASE_APP_HOME}/clazz @${BASE_APP_HOME}/sources.txt
[root@k8smaster01 daima]# sh javac.sh #执行编译
CLASSPATH=/data/java/daima/Test/config:/data/java/daima/Test/lib/gson-2.3.jar:.:/data/java/jdk18/lib/dt.jar:/data/java/jdk18/lib/tools.jar
/data/java/daima/Test/src/com/json/Test.java
/data/java/daima/Test/src/com/data/ParaMap.java
[root@k8smaster01 daima]# cp -r Test/clazz/com/ Test/config/ #拷贝编译后的文件到config目录
[root@k8smaster01 daima]# ls -lrt Test/config/
total 0
drwxr-xr-x 4 root root 28 Mar 4 00:08 com
[root@k8smaster01 daima]#
[root @ k8smaster01 daima] # after more java.sh # run the compiled file
#! / bin / bash
PROCESS_NAME=test_java
BASE_APP_HOME="/data/java/daima/Test"
jars=`ls ${BASE_APP_HOME}/lib`
for jar in $jars
do
CLASSPATH=${BASE_APP_HOME}/lib/$jar:$CLASSPATH
done
CLASSPATH="${BASE_APP_HOME}/config:${CLASSPATH}"
export CLASSPATH
echo "CLASSPATH=${CLASSPATH}"
java -cp ${CLASSPATH} com.json.Test
[root@k8smaster01 daima]# sh java.sh #运行编译后的文件,正常打印json串
CLASSPATH=/data/java/daima/Test/config:/data/java/daima/Test/lib/gson-2.3.jar:.:/data/java/jdk18/lib/dt.jar:/data/java/jdk18/lib/tools.jar
{"log":"348a8a27e315e5a26c68a002.348a8a27e315e5a26c68a003.0","localForceNewThread":"true","uuid":"28bcf60840f8416e8ea55ffe970c1623"}
[root@k8smaster01 daima]#
Link: https: //pan.baidu.com/s/1ZLHiJ9fapVzjYV7BkIisrg relevant code