构建与编译 (Java)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2650168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Building vs. Compiling (Java)
提问by sixtyfootersdude
Thinking that the answer to this is pretty obvious but here it goes:
认为这个问题的答案很明显,但它是这样的:
When I am working on a small project for school (in java) I compileit.
当我为学校(在 Java 中)做一个小项目时,我会编译它。
On my coop we are using ant to buildour project.
在我的鸡舍上,我们使用 ant 来构建我们的项目。
I think that compiling is a subset of building. Is this correct? What is the difference between building and compiling?
我认为编译是构建的一个子集。这样对吗?构建和编译有什么区别?
Related:
What is the difference between compiling and building?
相关:
编译和构建有什么区别?
采纳答案by Pascal Thivent
The "Build" is a process that covers all the steps required to create a "deliverable" of your software. In the Java world, this typically includes:
“构建”是一个过程,涵盖了创建软件“可交付成果”所需的所有步骤。在 Java 世界中,这通常包括:
- Generating sources (sometimes).
- Compiling sources.
- Compiling test sources.
- Executing tests (unit tests, integration tests, etc).
- Packaging (into jar, war, ejb-jar, ear).
- Running health checks (static analyzers like Checkstyle, Findbugs, PMD, test coverage, etc).
- Generating reports.
- 生成源(有时)。
- 编译源。
- 编译测试源。
- 执行测试(单元测试、集成测试等)。
- 包装(成jar、war、ejb-jar、ear)。
- 运行健康检查(静态分析器,如 Checkstyle、Findbugs、PMD、测试覆盖率等)。
- 生成报告。
So as you can see, compiling is only a (small) part of the build (and the best practice is to fully automate all the steps with tools like Maven or Ant and to run the build continuously which is known as Continuous Integration).
如您所见,编译只是构建的(小)部分(最佳实践是使用 Maven 或 Ant 等工具完全自动化所有步骤,并连续运行构建,这称为持续集成)。
回答by Tom
In simple words
简单来说
Compilation translates java code (human readable) into bytecode, so the Virtual machine understands it.
Building puts all the compiled parts together and creates (builds) an executable.
编译将 Java 代码(人类可读)翻译成字节码,以便虚拟机理解它。
构建将所有编译的部分放在一起并创建(构建)一个可执行文件。
回答by Kaili
Compilingis the act of turning source code into object code.
编译是将源代码转换为目标代码的行为。
Linkingis the act of combining object code with libraries into a raw executable.
链接是将目标代码与库组合成原始可执行文件的行为。
Buildingis the sequence composed of compilingand linking, with possibly other tasks such as installer creation.
构建是由编译和链接组成的序列,可能还有其他任务,如安装程序创建。
Many compilers handle the linkingstep automatically after compiling source code.
许多编译器在编译源代码后自动处理链接步骤。
What is the difference between compile code and executable code?
回答by drekka
Actually you are doing the same thing. Ant is build system based on XML configuration files that can do a wide range of tasks related to compiling software. Compiling your java code is just one of those tasks. There are many others such as copying files around, configuring servers, assembling zips and jars, and compiling other languages such as C.
其实你也在做同样的事情。Ant 是基于 XML 配置文件的构建系统,可以执行与编译软件相关的广泛任务。编译您的 Java 代码只是这些任务之一。还有许多其他的工作,例如复制文件、配置服务器、组装 zip 和 jar 以及编译其他语言(例如 C)。
You don't need Ant to compile your software. You can do it manually as you are doing at school. Another alternative to Ant is a product called Maven. Both Ant and Maven do the same thing , but in quite different ways.
您不需要 Ant 来编译您的软件。您可以像在学校一样手动完成。Ant 的另一种替代品是名为 Maven 的产品。Ant 和 Maven 都做同样的事情,但方式完全不同。
回答by patrick-fitzgerald
Compiling is just converting the source code to binary, building is compiling and linking any other files needed into the build directory
编译只是将源代码转换为二进制,构建是编译并将所需的任何其他文件链接到构建目录中
回答by Darien
Some of the answers I see here are out-of-context and make more sense if this were a C/C++ question.
我在这里看到的一些答案是脱离上下文的,如果这是一个 C/C++ 问题,则更有意义。
Short version:
精简版:
- "Compiling" is turning .java files into .class files
- 'Building" is a generic term that includes compiling and other tasks.
- “编译”正在将 .java 文件转换为 .class 文件
- “构建”是一个通用术语,包括编译和其他任务。
"Building" is a genericterm describes the overallprocess which includes compiling. For example, the build process might include tools which generate Java code or documentation files.
“构建”是一个通用术语,描述了包括编译在内的整个过程。例如,构建过程可能包括生成 Java 代码或文档文件的工具。
Often there will be additional phases, like "package" which takes all your .class files and puts them into a .jar, or "clean" which cleans out .class files and temporary directories.
通常会有额外的阶段,比如“打包”,它将所有的 .class 文件放入一个 .jar 中,或者“清理”,它会清除 .class 文件和临时目录。
回答by Premraj
- Buildis a compiled version of a program.
- Compilemeans, convert (a program) into a machine-code or lower-level form in which the program can be executed.
- Build是程序的编译版本。
- 编译意味着,将(程序)转换为机器代码或程序可以执行的低级形式。
In Java: Build is a Life cycle contains sequence of named phases.
在 Java 中:构建是一个生命周期,包含一系列命名阶段。
for example: maven it has three build life cycles, the following one is default
build life cycle.
例如:maven 它有三个构建生命周期,下面一个是default
构建生命周期。
?validate - validate the project is correct and all necessary information is available
?compile - compile the source code of the project
?test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
?package - take the compiled code and package it in its distributable format, such as a JAR.
?integration-test - process and deploy the package if necessary into an environment where integration tests can be run
?verify - run any checks to verify the package is valid and meets quality criteria
?install - install the package into the local repository, for use as a dependency in other projects locally
?deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
回答by Sam
In Eclipse and IntelliJ, the build process consist of the following steps:
cleaning the previous packages,
validate,
compile,
test,
package,
integration,
verify,
install,
deploy.
在 Eclipse 和 IntelliJ 中,构建过程包括以下步骤:清理以前的包、验证、编译、测试、打包、
集成、验证、安装、部署。