Ant and Eclipse
Transcript of Ant and Eclipse
-
8/14/2019 Ant and Eclipse
1/23
-
8/14/2019 Ant and Eclipse
2/23
What is Ant?
A simple definition states that Ant is a
Java-based build tool.
-
8/14/2019 Ant and Eclipse
3/23
Of course that definition may just raise the
question in your mind "What is a buildtool?".
To answer that question, consider what is
required to build a software system.
-
8/14/2019 Ant and Eclipse
4/23
A typical Build Process
After writing the code, following tasks are accomplished
before delivering a finished product:
compiling, running programs (e.g. for testing purposes)documenting, packaging, and
deploying the software you develop. Performing these steps by hand is tedious, repetitious, and
error-prone.
This is a task begging to be automated.
-
8/14/2019 Ant and Eclipse
5/23
-
8/14/2019 Ant and Eclipse
6/23
Eclipse and Ant
We know that Eclipse is a good IDE forJavaprojects
- user friendly tool forwriting and compilingJava code the most obvious part of softwaredevelopment
It also has JUnit as a plug-in
- a standard tool forunit testing
Eclipse has Ant as one more plug-in
-
8/14/2019 Ant and Eclipse
7/23
Eclipse and Ant
To see how Ant works from inside ofEclipse we shouldbe able to
create the build directorystructure
separate thesource and build directories either in a new project, or in an existing project
import an existing project
either as an Eclipse originated project
or as an independent Ant originated project(not sotrivial)
create and edit an Ant build XML file
use default Anteditor
run Ant from inside ofEclipse
-
8/14/2019 Ant and Eclipse
8/23
Creating the build directory structure The first step in formalizing the build process is to clearly
separate files as
source files,
other resources,
temporary files (compiled files), and
deliverables (JAR, etc).
How to do this in Eclipse? Note that in Eclipse this is more than just creating new
directories.
-
8/14/2019 Ant and Eclipse
9/23
Separating the source and build
directories in a project Eclipse, by default, creates one and the same directory
path, according to thepackage, for
source and
compiled Java classes.
That is, compiled classes were in thesame place assource code:
seeHello project in Navigator view
But you know that build process (in Ant) requires to makeclear separation between
source files and
generated files.
-
8/14/2019 Ant and Eclipse
10/23
Separating the source and build
directories in a new project If you know from the beginning ofcreating a project, say,Proj, in Eclipse that you need a formal Ant build processthen, when creating a new project, you should do the
following: after choosing
File>New>Project>Java Project>Next, and
entering the name of a project Proj, insteadof accepting of defaults and clicking Finish
immediately after entering the project name,
you should clickNext to move to another dialog box
-
8/14/2019 Ant and Eclipse
11/23
Separating the source and build
directories in a new projectthen choosing Source tab
lets you to create the new source folder name (say,
src orsource)
Click on Create a new source (sub)folderof
the Proj folder:
Insert folder name src
ClickFinish
ClickFinish
-
8/14/2019 Ant and Eclipse
12/23
Separating the source and build
directories in a new project
We will get two subdirectoriesProj\srcProj\bin
bin is default in Eclipse forcompiledclasses
(seebin in Navigatorview)
-
8/14/2019 Ant and Eclipse
13/23
Separating the source and build directories in an
existing project
For already existing project Hellosuch aseparation in Package Explorer View is easilydescribed in general terms as follows:
rightclickon the project name Hello
create a newsource folder src forHello by choose
New->SourceFolder
move your source code into it (just drag-and-drop).
Eclipsetakes care of creating the new separate outputfolder (bin) and itssubdirectories for compiled classes.
In addition, when you build with Eclipse, itputs all theclass files in the right subdirectories.
-
8/14/2019 Ant and Eclipse
14/23
Separating the source and build directories in an existing
project
In more detail:
InJavaperspective,
right-click on the existingproject name Hello,
select New->SourceFolder,
enter src as the foldername.
Click Finish,
On the question concerningremoving all generatedresources (i.e., compiled
Java classes), click Yes.
-
8/14/2019 Ant and Eclipse
15/23
Separating the source and build directories in an existing
project
In the Package Explorerview,
Drag-and-drop org folder(with its subfolders, etc.)onto the src folder.
In the Navigator view (of theResource Perspective) wewill get the following picturewith separatedHelloWorld.java and
HelloWorld.class.
In the Package Explorerview(of theJava Perspective)
we will not see thecompiled class,
but we will see the
-
8/14/2019 Ant and Eclipse
16/23
Separating the source and build directories in an
existing project
We can additionally,create folders Hello\dist\lib
Hello\dist\doc
for distributable files like
HelloWorld.jar
and documentation.
-
8/14/2019 Ant and Eclipse
17/23
-
8/14/2019 Ant and Eclipse
18/23
Creating a simple Ant example ofbuild.xmlThen type in, for example, the following:
The Anteditor provides some basic conveniences, such as code-completion feature (by pressing Ctrl-Space).
Outside of a tag, it shows you available tags for sub elements;
Inside of a tag, it shows you the allowed attributes for that tag. It provides
syntax highlighting and an outline view.
-
8/14/2019 Ant and Eclipse
19/23
Running Ant inside of Eclipse
To runbuild.xml, first save it.
Then right-click onbuild.xml inthe Editor or in the PackageExplorer
Select either Run as > 1 Ant Build, and see
the next slide for the result, or,for more options,
Run as > 2 Ant Build (note `2and dots!)
In the opened dialog box
choose Targets tab
the default target is automaticallyselected,
but you can choose other targets
(here we have only one) click the Runbutton
-
8/14/2019 Ant and Eclipse
20/23
Running Ant inside of Eclipse
This produces the following output in Eclipses Console view:
Buildfile: H:\eclipse\Hello\build.xmlprint message: [echo] Hello from Ant!BUILD SUCCESSFULTotal time: 161 milliseconds
Note that selecting Run > 2 Ant Buildabove gives us thepossibility to choose any sequence of targets in the build file toexecute them in any order we want (and something more).
To re-run, click the button (the green part, not the black triangle;do not mix this button with the other similar button used for runningJava and JUnit classes).
-
8/14/2019 Ant and Eclipse
21/23
Default Ant Editor
The default editor for arbitrary .xml file (notnecessarilybuild.xml) is a
simple text editor (not adapted to work withy Antbuild files)
But we want to use build files with arbitrary names(say, our oldMYBUILD-07.xml),
Let us assigndefault Ant editor to any xmlfile (suchas, our old fileMYBUILD-07.xml).
Choose
Window > Preferences > General >
Editors > File Associations
-
8/14/2019 Ant and Eclipse
22/23
Default Ant Editor
-
8/14/2019 Ant and Eclipse
23/23
Thank you!
Presented by: Ankit Sharma
BPM-SOA Team