Building vs. Compiling (Java)

JavaBuildCompilation

Java Problem Overview


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 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?

Java Solutions


Solution 1 - Java

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:

  1. Generating sources (sometimes).
  2. Compiling sources.
  3. Compiling test sources.
  4. Executing tests (unit tests, integration tests, etc).
  5. Packaging (into jar, war, ejb-jar, ear).
  6. Running health checks (static analyzers like Checkstyle, Findbugs, PMD, test coverage, etc).
  7. 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).

Solution 2 - Java

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.

Solution 3 - Java

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.

https://stackoverflow.com/questions/2310261/what-is-the-difference-between-compiling-and-building

Solution 4 - Java

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.

Solution 5 - Java

  • 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.

Solution 6 - Java

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.

Solution 7 - Java

In Eclipse and IntelliJ, the build process consist of the following steps: cleaning the previous packages, validate, compile, test, package,
integration, verify, install, deploy.

Solution 8 - Java

Compiling is just converting the source code to binary, building is compiling and linking any other files needed into the build directory

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsixtyfootersdudeView Question on Stackoverflow
Solution 1 - JavaPascal ThiventView Answer on Stackoverflow
Solution 2 - JavaDarienView Answer on Stackoverflow
Solution 3 - JavaKailiView Answer on Stackoverflow
Solution 4 - JavaTomView Answer on Stackoverflow
Solution 5 - JavaPremrajView Answer on Stackoverflow
Solution 6 - JavadrekkaView Answer on Stackoverflow
Solution 7 - JavaSamView Answer on Stackoverflow
Solution 8 - Javapatrick-fitzgeraldView Answer on Stackoverflow