工具----javac,kotlinc的使用方式

前言

javac是日常中比较常见的工具之一,最近用到,但是获取不同的命令很不容易,这里记录一下命令。

编译一个文件

javac \
-d  /Users/haha/AndroidStudioProjects/Fixer/common/src/main/patch/ \
/Users/haha/AndroidStudioProjects/Fixer/common/src/main/java/com/github/pgycode/common/R.java

编译指定的文件夹下所有.java

1.一个比较真实的例子(linux下),\在表示换行 分号(;)在linux系统中为冒号(:)
2.演示了如果有多个classpath怎么处理,
3.find命令表示查找文件写入sources.txt
4.-classpath 选择依赖路径 -d 选择输出路径 @选择一个文本文件(包含你需要编译的文件)

find /Users/haha/AndroidStudioProjects/Fixer/common/src/main/java/ -name "*.java" > /Users/haha/AndroidStudioProjects/Fixer/common/src/main/java/sources.txt

javac \
-classpath \
/Users/haha/AndroidStudioProjects/Fixer/common/src/main/patch/:\
/Users/haha/AndroidStudioProjects/Fixer/common/build/intermediates/classes/debug:\
/Users/haha/AndroidStudioProjects/Fixer/common/build/tmp/kotlin-classes/debug:\
/Users/haha/AndroidStudioProjects/Fixer/common/build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r:\
/Users/haha/Library/Android/sdk/platforms/android-28/android.jar:\
/Applications/'Android Studio.app'/Contents/jre/jdk/Contents/Home/jre/lib/rt.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/android.arch.core/common/1.1.0/8007981f7d7540d89cd18471b8e5dcd2b4f99167/common-1.1.0.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/runtime-1.1.0.aar/10b1f6b8f2ba98332a3f44ed91c74c01/jars/classes.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/android.arch.lifecycle/common/1.1.0/edf3f7bfb84a7521d0599efa3b0113a0ee90f85/common-1.1.0.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/livedata-core-1.1.0.aar/c0913c3ed70ca36853f757fab9e8d2f7/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/runtime-1.1.0.aar/d06991193cd4653275f11bfb6b6ba35a/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/viewmodel-1.1.0.aar/01a2ffa6c12790703833d6ab4359336a/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/constraint-layout-1.1.0.aar/2197d603e3769bdaf22c63f538ff0b51/jars/classes.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/com.android.support.constraint/constraint-layout-solver/1.1.0/931532e953a477f876f2de18c2e7f16eee01078f/constraint-layout-solver-1.1.0.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/espresso-core-3.0.2.aar/797656f3983a75f253521ad1a6b5fce7/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/espresso-idling-resource-3.0.2.aar/52a32ce59857427f0cc1c7043b87821e/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/monitor-1.0.2.aar/ed5ef94de277f4b4520243845b2b1cc1/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/runner-1.0.2.aar/d2a7cdc2a868d6ca302f123fee1c7824/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/animated-vector-drawable-27.1.1.aar/df0b63207dbd1bc7851a004cd78d5a99/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.1.1.aar/f495c322ce5e608d2d36e91838826fd1/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/multidex-1.0.2.aar/75b26e4140a68f278c69c76986026bf8/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/multidex-instrumentation-1.0.2.aar/7294af794ea983f44b622aa1b35d66db/jars/classes.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/com.android.support/support-annotations/27.1.1/39ded76b5e1ce1c5b2688e1d25cdc20ecee32007/support-annotations-27.1.1.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/support-compat-27.1.1.aar/6d794637795dd07c328cf641810e3b74/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/support-core-ui-27.1.1.aar/dc717b9c332ba568033c38205c289b5e/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/support-core-utils-27.1.1.aar/03fc3a1a407cfcc3bfef40d84f82e8ab/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/support-fragment-27.1.1.aar/fcbe73235ba1c97ef0a0488044d7891f/jars/classes.jar:\
/Users/haha/.gradle/caches/transforms-1/files-1.1/support-vector-drawable-27.1.1.aar/c341819ef5e8005ad8104b1735dbede3/jars/classes.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/2.0.1/516c03b21d50a644d538de0f0369c620989cd8f0/jsr305-2.0.1.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/com.squareup/javawriter/2.1.1/67ff45d9ae02e583d0f9b3432a5ebbe05c30c966/javawriter-2.1.1.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/javax.inject/javax.inject/1/6975da39a7040257bd51d21a231b76c915872d38/javax.inject-1.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/net.sf.kxml/kxml2/2.3.0/ccbc77a5fd907ef863c29f3596c6f54ffa4e9442/kxml2-2.3.0.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.3/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-integration/1.3/5de0c73fef18917cd85d0ab70bb23818685e4dfd/hamcrest-integration-1.3.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-library/1.3/4785a3c21320980282f9f33d0d1264a69040538f/hamcrest-library-1.3.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.21/4bcc2012b84840e19e1e28074284cac908be0295/kotlin-stdlib-1.3.21.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.21/f30e4a9897913e53d778f564110bafa1fef46643/kotlin-stdlib-common-1.3.21.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.21/d207ce2c9bcf17dc8e51bab4dbfdac4d013e7138/kotlin-stdlib-jdk7-1.3.21.jar:\
/Users/haha/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar \
-d /Users/haha/AndroidStudioProjects/Fixer/common/src/main/patch/ \
@/Users/haha/AndroidStudioProjects/Fixer/common/src/main/java/sources.txt

rm /Users/haha/AndroidStudioProjects/Fixer/common/src/main/java/sources.txt

编译自己指定的一些.java

第一步:自己使用工具把你要编译的那些文件绝对路径导入到一个文本文件中。

第二步:指定编译后目录,编译目标的记录文本文件,classpath依赖包,几乎同上。

备注

kotlinc 的使用方式几乎和javac相同

你可能感兴趣的:(工具----javac,kotlinc的使用方式)