views:

217

answers:

6

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?

+2  A: 

In simple words

Compilation traslates java code (human readable) into bytecode, so the Virtual machine understands it.

Building puts all the compiled parts togheter and creates (builds) an executable.

Tom
+6  A: 

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.

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

Shadow
Some other possible tasks: enhancing (JDO), Javadoc-ing, packaging, and signing. In addition, some environments including running automated unit/regression tests as part of a "build".
Bert F
Normally, there is no linking step when building Java projects, and no raw executable is produced. Rather, the compiled classes are packaged together into a .jar file as part of the build. (Or .war, or .ear, depending on your target environment.)
markusk
Pascal Thivent
+2  A: 

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.

Derek Clarkson
You can also see what ant is actually doing by looking the buildfile (most likely called build.xml). Even if you're not familiar with the syntax, you can kind of see what's going on. <javac> means it's compiling some Java code. <java> means it's actually running the compiled code. Probably it's creating a directory to put the .class files in, compiling the code, maybe creating some Javadoc, etc.
MatrixFrog
A: 

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

paddydub
+7  A: 

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.

Darien
+7  A: 

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

Pascal Thivent