【发布时间】:2011-02-08 15:51:05
【问题描述】:
认为这个问题的答案很明显,但它就是这样:
当我在为学校(在 java 中)做一个小项目时,我编译它。
在我的合作社中,我们使用 ant 来构建我们的项目。
我认为编译是构建的一个子集。它是否正确?构建和编译有什么区别?
【问题讨论】:
标签: java build compilation
认为这个问题的答案很明显,但它就是这样:
当我在为学校(在 java 中)做一个小项目时,我编译它。
在我的合作社中,我们使用 ant 来构建我们的项目。
我认为编译是构建的一个子集。它是否正确?构建和编译有什么区别?
【问题讨论】:
标签: java build compilation
简单来说
编译翻译java代码(人工 可读)转换成字节码,所以 虚拟机可以理解。
Building 将所有已编译的部分 一起创造(建立)一个 可执行文件。
【讨论】:
编译是将源代码转换为目标代码的行为。
链接是将目标代码与库组合成原始可执行文件的行为。
构建是由编译和链接组成的序列,可能还有其他任务,例如创建安装程序。
许多编译器在编译源代码后会自动处理链接步骤。
What is the difference between compile code and executable code?
【讨论】:
【讨论】:
编译只是将源代码转换为二进制,构建是编译并将所需的任何其他文件链接到构建目录中
【讨论】:
我在这里看到的一些答案是断章取义的,如果这是一个 C/C++ 问题,则更有意义。
短版:
“构建”是一个通用术语,描述了包括编译在内的整体过程。例如,构建过程可能包括生成 Java 代码或文档文件的工具。
通常会有其他阶段,例如“打包”将所有 .class 文件放入 .jar 中,或“清理”将 .class 文件和临时目录清除。
【讨论】:
“构建”是一个涵盖创建软件“可交付成果”所需的所有步骤的过程。在 Java 世界中,这通常包括:
如您所见,编译只是构建的一小部分(最佳实践是使用 Maven 或 Ant 等工具完全自动化所有步骤并连续运行构建,这被称为 @987654321 @)。
【讨论】:
在 Java 中:构建是一个生命周期,包含一系列命名阶段。
例如: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.
【讨论】:
在 Eclipse 和 IntelliJ 中,构建过程包括以下步骤:
清理以前的包裹,
证实,
编译,
测试,
包,
一体化,
核实,
安装,
部署。
【讨论】: