javac 编译java

javac is a tool used to compile Java applications or source code. javac reads class and interface definitions and compiles them into bytecode class files. These class files have *.class extension.

javac是用于编译Java应用程序或源代码的工具。 javac读取类和接口定义,并将其编译为字节码类文件。 这些类文件具有* .class扩展名。

句法 (Syntax)

javac usage syntax is a bit complex according to generally Linux tools.

根据一般Linux工具,javac使用语法有点复杂。

javac OPTIONS SOURCEFILES CLASSES ARGFILES
  • OPTIONS are used to specify command-line options provided by javacOPTIONS用于指定javac提供的命令行选项
  • SOURCEFILES are used to specify one or more source files to be compiledSOURCEFILES用于指定一个或多个要编译的源文件
  • CLASSES are used to specify one or more classes to be processed for annotations such as YourPackage.YourClassCLASSES用于为注释(如YourPackage.YourClass)指定要处理的一个或多个类。
  • ARGFILES are used to specify one or more files that contain options and sources filesARGFILES用于指定一个或多个包含选项和源文件的文件

显示Javac版本(Show Javac Version)

Java Development Kit(JDK)  and Java Runtime Environment(JRE) can have different versions we target this will also affect the version of the javac. If we want to use specific Java programming language version we need to check the javac version with the  --version.

Java开发套件(JDK)和Java运行时环境(JRE)可以具有我们所针对的不同版本,这也将影响javac的版本。 如果要使用特定的Java编程语言版本,则需要使用--version检查javac版本。

$ javac --version

Show Javac Version
显示Javac版本

编译Java源代码(Compile Java Source Code)

We will start with a simple javac example where we will compile a single Java source code file. As we know Java source code files generally use *.java extension. We will just provide the file name to the javac compiler which is my.java in this example.

我们将从一个简单的javac示例开始,在该示例中,我们将编译一个Java源代码文件。 众所周知,Java源代码文件通常使用* .java扩展名。 我们仅将文件名提供给javac编译器,在此示例中为my.java。

We will use the following sample HelloWorld.java source code file. We will try to compile this Java source file with the javac command line tool.

我们将使用以下示例HelloWorld.java源代码文件。 我们将尝试使用javac命令行工具编译此Java源文件。

/*FileName : "HelloWorld.java" Example Application" */class HelloWorld
{ public static void main(String args[]) { System.out.println("Hello, World"); }
}

Below we will provides the java source file name HelloWorld.java which will compile and create the compiled byte code file named HelloWorld.class. As you can see the new extension is .class which is a compiled Java class file.

下面,我们将提供Java源文件名称HelloWorld.java,它将编译并创建名为HelloWorld.class的已编译字节代码文件。 如您所见,新扩展名是.class ,它是一个已编译的Java类文件。

$ javac HelloWorld.java$ file HelloWorld.class

编译多个Java文件 (Compile Multiple Java Files)

In the previous example, we have compiled a single Java file. But this is insufficient for big projects where we need to compile multiple Java files in a single command. We can specify multiple Java files to the javac in order to compile to the byte code. We will just append the file names by separating them with spaces.

在前面的示例中,我们已经编译了一个Java文件。 但这对于大型项目是不够的,在大型项目中,我们需要在一个命令中编译多个Java文件。 我们可以为javac指定多个Java文件,以便编译为字节码。 我们将通过用空格分隔它们来追加文件名。

$ javac HelloWorld.java HiWorld.java IAmHere.Java

编译所有Java文件 (Compile All Java Files)

We can also compile all java files in the specified directory we will just use asterisk and .java to specify files with java extension in the current directory.

我们还可以编译指定目录中的所有Java文件,我们将仅使用星号和.java在当前目录中指定带有Java扩展名的文件。

$ javac *.java

We can also specify a different directory from the current working directory. In this example, we will compile all Java files residing in /home/ismail/MyProject.

我们还可以指定与当前工作目录不同的目录。 在此示例中,我们将编译/home/ismail/MyProject所有Java文件。

$ javac /home/ismail/MyProject/*.java

在详细模式下打印详细的编译日志 (Print Detailed Compile Log In Verbose Mode)

During compilation, we may need to print detailed information like libraries, operations warnings etc. We can use the -verbose option which will provide detailed debug information about the compile operation.

在编译期间,我们可能需要打印详细信息,例如库,操作警告等。我们可以使用-verbose选项,该选项将提供有关编译操作的详细调试信息。

$ javac -verbose HelloWorld.java

Print Detailed Compile Log In Verbose Mode
在详细模式下打印详细的编译日志

指定Java文件和文件中的选项(Specify Java Files and Options From File)

Up to now, we have provided the Java files and options from the interactive shell or command line. If there are a lot of detailed file names and options where we will run them over and over again we can use files to specify the Java file named and options. We will use a file named config which will provide Java files and javac option to the javac command. We will use @ sign before the config file.

到目前为止,我们已经从交互式外壳程序或命令行中提供了Java文件和选项。 如果有很多详细的文件名和选项,我们将一遍又一遍地运行它们,我们可以使用文件来指定名为和选项的Java文件。 我们将使用一个名为config的文件,它将为javac命令提供Java文件和javac选项。 我们将在配置文件之前使用@符号。

.u8b0e7a8f76295deed8ca504ee1352856 , .u8b0e7a8f76295deed8ca504ee1352856 .postImageUrl , .u8b0e7a8f76295deed8ca504ee1352856 .centered-text-area { min-height: 80px; position: relative; } .u8b0e7a8f76295deed8ca504ee1352856 , .u8b0e7a8f76295deed8ca504ee1352856:hover , .u8b0e7a8f76295deed8ca504ee1352856:visited , .u8b0e7a8f76295deed8ca504ee1352856:active { border:0!important; } .u8b0e7a8f76295deed8ca504ee1352856 .clearfix:after { content: ""; display: table; clear: both; } .u8b0e7a8f76295deed8ca504ee1352856 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u8b0e7a8f76295deed8ca504ee1352856:active , .u8b0e7a8f76295deed8ca504ee1352856:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u8b0e7a8f76295deed8ca504ee1352856 .centered-text-area { width: 100%; position: relative; } .u8b0e7a8f76295deed8ca504ee1352856 .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u8b0e7a8f76295deed8ca504ee1352856 .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u8b0e7a8f76295deed8ca504ee1352856 .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u8b0e7a8f76295deed8ca504ee1352856:hover .ctaButton { background-color: #E67E22!important; } .u8b0e7a8f76295deed8ca504ee1352856 .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u8b0e7a8f76295deed8ca504ee1352856 .u8b0e7a8f76295deed8ca504ee1352856-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u8b0e7a8f76295deed8ca504ee1352856:after { content: ""; display: block; clear: both; }

LEARN MORE  Php Tutorial

.u8b0e7a8f76295deed8ca504ee1352856 , .u8b0e7a8f76295deed8ca504ee1352856 .postImageUrl , .u8b0e7a8f76295deed8ca504ee1352856 .centered-text-area { min-height: 80px; position: relative; } .u8b0e7a8f76295deed8ca504ee1352856 , .u8b0e7a8f76295deed8ca504ee1352856:hover , .u8b0e7a8f76295deed8ca504ee1352856:visited , .u8b0e7a8f76295deed8ca504ee1352856:active { border:0!important; } .u8b0e7a8f76295deed8ca504ee1352856 .clearfix:after { content: ""; display: table; clear: both; } .u8b0e7a8f76295deed8ca504ee1352856 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u8b0e7a8f76295deed8ca504ee1352856:active , .u8b0e7a8f76295deed8ca504ee1352856:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u8b0e7a8f76295deed8ca504ee1352856 .centered-text-area { width: 100%; position: relative; } .u8b0e7a8f76295deed8ca504ee1352856 .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u8b0e7a8f76295deed8ca504ee1352856 .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u8b0e7a8f76295deed8ca504ee1352856 .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u8b0e7a8f76295deed8ca504ee1352856:hover .ctaButton { background-color: #E67E22!important; } .u8b0e7a8f76295deed8ca504ee1352856 .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u8b0e7a8f76295deed8ca504ee1352856 .u8b0e7a8f76295deed8ca504ee1352856-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u8b0e7a8f76295deed8ca504ee1352856:after { content: ""; display: block; clear: both; }

了解更多PHP教程

Here is the config file content which is used in previous examples.

这是在先前示例中使用的配置文件内容。

HelloWorld.java-verbose

We will provide this config file with the @ sign like below. Keep in mind that we can use a different name than config for this feature.

我们将为该配置文件提供@符号,如下所示。 请记住,对于此功能,我们可以使用与config不同的名称。

$ java @config

Specify JavaFiles and Options From File
从文件中指定JavaFiles和选项

指定目标路径(Specify The Destination Path)

After given Java files are compiled into byte code the new files are stored in the current working directory. These files will have the same name as the source file and extension will be class. We can specify different output or destination path to put created byte code or binary files We will use -d option and the destination path.

在将给定的Java文件编译为字节代码之后,新文件将存储在当前工作目录中。 这些文件将与源文件具有相同的名称,并且扩展名将为class。 我们可以指定不同的输出或目标路径来放置创建的字节码或二进制文件。我们将使用-d选项和目标路径。

$ javac -d  /home/ismail/binary HelloWorld.java

指定类路径 (Specify Class Path)

If we need to provide types required to compile our source file we can use the -cp option and provide classpath like below. If this option is not provided the CLASSPATH environment variable will be used.

如果我们需要提供编译源文件所需的类型,则可以使用-cp选项并提供如下所示的类路径。 如果未提供此选项,则将使用CLASSPATH环境变量。

$ javac -cp /bin/lib/MyProject HelloWorld.java

指定模块或库路径 (Specify The Module or Library Path)

We can also use -p option in order to specify modules location. But this option can be used after Java 9.

我们也可以使用-p选项来指定模块的位置。 但是此选项可以在Java 9之后使用。

$ javac -p /bin/lib/MyProject HelloWorld.java

翻译自: https://www.poftut.com/how-to-compile-java-source-code-with-javac-tool/

javac 编译java

javac 编译java_如何使用Javac工具编译Java源代码?相关推荐

  1. apt编译java_自动生成代码工具--APT

    APT(Annotation Processing Tool)注解处理器,是javac的一个工具,它用来在编译时扫描和处理注解(Annotation).它可以生成Java代码,同时这些代码会跟手工白那 ...

  2. 源码编译系列之mpv播放器编译教程

    源码编译系列之mpv播放器编译教程 编译mpv播放器有两种方法: 手工下载mpv源码编译,然后编译安装,. 通过mpv-build工具编译安装,编译简单,依赖库版本脚本自动下载,但跟X相关库问题还是需 ...

  3. java高仿新浪微博短链接地址生成工具ShortUrlGenerator.java

    原文:仿新浪微博 短链接地址生成工具 ShortUrlGenerator.java 源代码下载地址:http://www.zuidaima.com/share/1550463378934784.htm ...

  4. Java基础 - javac命令详解(1) 编译基本java项目

    1.为什么要搞定 javac 命令 1.javac 是java中的编译源代码的命令工具,将.java文件编译成 .class 文件: 2.由于当下为了提高开发效率,大多数的开发工作都在 java的 集 ...

  5. java文件编译_【java】javac编译多个有依赖关系的java文件为class文件

    历史文章: [javac命令不能使用,提示不是内部命令或外部命令,请查看历史文章] =================需求说明========================== 之前的文章中,仅说明 ...

  6. 无ide编译java_无IDE编译和运行java

    建立和运行Java代码 为了对这篇文章进行更具体的讨论,我将使用一些非常简单的Java类,在同一个包中通过彼此相关的组合或继承(不在 未命名的包中)来调用dustin.examples.这两个在第三个 ...

  7. ultraedit运行java_如何在UltraEdit中编译和运行Java程序

    如何在UltraEdit中编译和运行Java程序 (2011-07-28 12:33:52) 标签: it 问题提出: 可以毫不夸张地说,JDK+UltraEdit是面向Java初学者的开发工具的绝配 ...

  8. sublime怎么编译java_文本编辑利器:Sublime Text3 编译运行Java程序

    步骤 JDK(Java 开发环境需要提前配置好) Sublime Text3 (具体的安装方式参考之前文章: 简书 个人博客) 直接在安装路径下找到*\Packages\Java.sublime-pa ...

  9. Windows下适用于PHP 7.1的memcache扩展工具编译

    项目里需要PHP支持memcache扩展,首先来介绍一下memcache是啥吧 介绍 memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前 ...

最新文章

  1. 禁止显示“You have new mail in /var/spool/mail/root”
  2. 华为鸿蒙系统新机发布时间,华为鸿蒙OS发布会定档,或将有多款新机亮相
  3. Docker(一):Docker入门教程
  4. 容器学习 之 容器的概念(一)
  5. ubuntu12.04samba服务器配置
  6. 如何遍历JavaScript中的对象
  7. 训练史上最佳GAN用了512块TPU,一作自述:这不是算法进步,是算力进步
  8. 新技能 get —— 五笔打字
  9. mac os x 10.11 php7,mac osx 10.11.2安装PHP7提示“configure: error: libcrypto not found!”
  10. Spring MVC @ExceptionHandler、@ControllerAdvice、@RestControllerAdvice 统一异常处理
  11. 金蝶KIS专业版二次开发探索
  12. NGINX集群+KeepLived实现高可用
  13. 使用opencv在视频中插入文字、图片;生成特定文字视频
  14. python自带的库有哪些_python自带库
  15. [精简]托福核心词汇64
  16. 【房屋销售系统——开题报告 分享(仅供参考呀)】
  17. webView系列(五)----历史记录
  18. 《设计模式》(精华集)
  19. 《历术甲子篇》冬至合朔表
  20. java privatekey输出字符串_根据字符串(String)生成公钥(PublicKey)和私钥(PrivateKey)对象...

热门文章

  1. autojs-抖音评论
  2. Kubernetes笔记(九) Kubernetes 应用封装与扩展
  3. RegEx (15) - 使用字符 \D 不包含数字
  4. 管理系统中计算机应用知识总结,自考管理系统中计算机应用各知识点梳理.doc...
  5. PYTHON用时变马尔可夫区制转换(MRS)自回归模型分析经济时间序列
  6. 蜗牛学院:软件测试工程师的8种技能
  7. 学习用 doxygen 生成源码文档
  8. 一分钟带你解决“command not found“报错
  9. 使用Hydra破解弱密码
  10. 软件开发管理与质量控制(一)