JDBC Dao pattern:
Build tool : Maven
===============
Build Process in java based project/application management:
--------------------------------------------------------------------------
develpers duty/responsibility to develop a java based business application:
1. write some source code(bunch of classes, inteface...)
2.add some external jarfiles to the classpath (dependencies)
in JDBC dao project, driver jar file is the dependency of our project.
3.compile the code.
4.prepare some test cases.
5.add Junit/mockito related jar files inside the classpath
6.compile and run the test cases.
7.arrange our code in a standard folder structure
8.Do the packaging : build the jar, war file.
9.deploy this jar file/ war file to the server.
--if any mistake identified then developer performs above task again and again.
build process: keeping our project ready for execution/release is called build
process.
--manually doing this build process will increase the burden on developer
--to automate this build process of java applicaiton , apache foundation released
a tool called ANT (Another Neet Tool).
the problem with ANT tool is :
1. ANT does not have the capabilities of donwloading the required jar files from
internate automatically.
2. It can not prepare,compile and run the test cases automatically.
3.In ANT we need to write a build.xml file which is very lenghty xml file.
As a solution Apache foundation released another build tool called Maven.
--Gradle
--we can develop java application using Maven by 2 ways:
1.using console based (here we need to download the maven s/w and install it in our
local computer ,and then we need to set path and some environment variable to
develop java application)
2.using IDE: here we don't need to install any kind of extra s/w.
STS has inbuilt support of Maven and Gradle
Maven terminology:
===============
1. artifact :-
--An artifact is an outcome in maven, it can be a file, .class file or a jar file,
war file,ear file,etc.
2. archetype:-
--it is project template for creating similar type of project in maven.
3. Groupid:
--it is an Id used to identify the artifacts of a perticular organization (naming
convention is similar to package name.) com.masai
4.artiactid : it is the id for the final outcome (artifactid name will be the root
folder of our application)
5.pom.xml : (project object model) : all the information will be their in this
file.
--in this model, entire application itself will be considered as an object.
it defines following properties for a project:
1. Name
2.version
3. packaging (jar, war, ear)
4.dependecnies : required jar files.
5.plugins: will inhance the functionality of our project.
docker
jenkins (CI/CD)
Maven Repository:
================
-- a repository is a store where maven maintains plugins, archetypes, and lots of
jar files used for building different kinds of java projects.
maven repo are of 3 types:
1.central repo :- it is the maven's own repo in which it maintains all kinds of
project related plugins, archetypes, jars etc.
https://repo1.maven.org/maven2
2.remote repo : this repo is maintained within the organization for sharing
plugins, archetypes and jar files for multiple projects withing orgnizations.
3.local repo: this repo will be created inside the developer computer. (.m2) is
the name for this repo.
mysql-connector.jar
pom.xml:
.m2 ---
maven build life cycle:
==================
maven build life cycle contains diff phases:
1. validate: - in this phase it will verify the project diectory structure is valid
or not. and it has pom.xml file is there or not.
2.compile: maven compiles all the source code of the project by downloading and
adding requied jar files in the classpath.
3.test-compile: if we have written any unit test cases those code will be compiled.
4.test : maven will run all the test cases and it will show how many test cases are
success and how many fails.
5.package : maven will bundle our java code into a jar file inside 'target' folder.
6.install : that jar file in step 5 will be stored in the localrepo.
7.deploy : maven stores the application jar file to the central repo.
8.clean : here maven will delete and remove all the files that are generated in
previous build.
Note: if we execute any phase to build the maven project then maven will execute
all the phases till that given phase.
mvn clean :- remove and delete previous build
mvn test : till the test phase.
mvn deploy:
mvn validate:
src/main/java : -- here we need to place our source code
src/main/resources : any xml file, properties files, text files
src/test/java : -- here we need to place our source code to unit testing
src/test/resources : any xml file, properties files, text files to unit testing
after creating a maven project we need to change the java version of the maven
project from jdk 5 to jdk 8
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
after pasting the above tag inside the pom.xml file we need to update our maven
project:
right click on the project--->maven ---> update maven project.