Building vs. Compiling (Java)
Thinking that the answer to this is pretty obvious but here it goes:
When I am working on a开发者_如何学Go small project for school (in java) I compile it.
On my coop we are using ant to build our project.
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?
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:
- 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.
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).
Some of the answers I see here are out-of-context and make more sense if this were a C/C++ question.
Short version:
- "Compiling" is turning .java files into .class files
- 'Building" is a generic term that includes compiling and other tasks.
"Building" is a generic term describes the overall process which includes compiling. For example, the build process might include tools which generate Java code or documentation files.
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.
Compiling is the act of turning source code into object code.
Linking is the act of combining object code with libraries into a raw executable.
Building is the sequence composed of compiling and linking, with possibly other tasks such as installer creation.
Many compilers handle the linking step automatically after compiling source code.
What is the difference between compile code and executable code?
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.
- Build is a compiled version of a program.
- Compile means, convert (a program) into a machine-code or lower-level form in which the program can be executed.
In Java: Build is a Life cycle contains sequence of named phases.
for example: maven it has three build life cycles, the following one is default
build life cycle.
◾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.
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.
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.
Lookup Ant and Maven for more details.
In Eclipse and IntelliJ, the build process consist of the following steps:
cleaning the previous packages,
validate,
compile,
test,
package,
integration,
verify,
install,
deploy.
Compiling is just converting the source code to binary, building is compiling and linking any other files needed into the build directory
精彩评论