Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typical build process of Java application

Tags:

java

Being new to Java, I am not able to understand the complete build process from source code to hardware specific binaries. Basically I am using Eclipse for java and would like to know what all conversions takes place from source code(.java) to binary, what all files are linked using some linker, preprocessor etc etc.

Shall appreciate if you can point me to some link giving detail of complete build process for java. I have already searched this forum but did not get detail info.

Thanks

Edited:

So to be more precise I am looking for java equivalent of following build process in C: I googled a lot but no gain! A figure like the following is not a must(though preferred), but if you can write 'n' sequential/parallel steps involved in complete Java build process, that will be really appreciated. Though much of the information provided by @Tom Anderson is very useful to me.

enter image description here

like image 344
gpuguy Avatar asked May 08 '12 11:05

gpuguy


People also ask

What is the build process in 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: Generating sources (sometimes). Compiling sources. Compiling test sources.

What happens in build process?

What Does Build Mean? The term build may refer to the process by which source code is converted into a stand-alone form that can be run on a computer or to the form itself. One of the most important steps of a software build is the compilation process, where source code files are converted into executable code.

What is the execution process of Java program?

In Java, programs are not compiled into executable files; they are compiled into bytecode (as discussed earlier), which the JVM (Java Virtual Machine) then executes at runtime. Java source code is compiled into bytecode when we use the javac compiler.


1 Answers

The first thing to appreciate is that your question contains a mistaken assumption. You ask about "the complete build process from source code to hardware specific binaries" - but the normal Java build process never produces architecture-specific binaries. It gets as far as architecture-independent bytecode, then stops. It's certainly true that in most cases, that bytecode will be translated into native code to be executed, but that step happens at runtime, inside the JVM, entirely in memory, and does not involve the production of binary files - it is not part of the build process.

There are exceptions to this - compilers such as GCJ can produce native binaries, but that is rarely done.

So, the only substantial step that occurs as part of a build process is compilation. The compiler reads in source code, does the usual parsing and resolution steps, and emits bytecode. That process is not in any way specified; as is usual, the language specification defines what the elements of the language are, and what they mean, but not how to compile them. What is specified in the format of the output: the bytecode is packaged in the form of class files, one per class, which in turn may be grouped together in jar files for ease of distribution.

When the class files come to be executed, there are then further steps needed before execution is possible. These are quite well-specified in the chapter on loading, linking, and initializing in the JVM specification. But, as i said, these are not really part of the build process.

There are a few other steps that may occur in a build process, usually prior to compilation: dependencies might be resolved and downloaded, resources might be copied and converted between character sets, and code might be generated. But none of this is standard, it's all stuff that's added on to the core process of compilation by various build tools.

like image 59
Tom Anderson Avatar answered Oct 29 '22 03:10

Tom Anderson