Java:
Java is an object oriented programming language. It is built to have as few dependencies as possible on implementation. It is Write once, run anywhere (WORA) platform. The Compiled Java code will run on all Java-supporting platforms without recompilation.
What is maven in Java?
Maven is a strong, POM-based project management tool (project object model). This is used for the design, maintenance, and documentation of projects. It simplifies the process of building as in ANT. But it is way too far advanced than ANT.
We can say in short terms that maven is a tool that can be used to create and manage any Java-based project. Maven supports the day-to-day work of Java developers. It generally helps to understand any Java-based project.
To get in-Depth knowledge on Java you can enroll for a live demo on Java Online Training
Maven repository:
Maven repositories are folders with some metadata on bundled JAR files. The metadata are POM files relating to the projects belonging to each packaged JAR object, including what external dependencies each packaged JAR has to provide. This metadata helps Maven to recursively download dependencies until all dependencies are downloaded.Then insertion to local machine takes place.
Maven has three repository types:
- Local Repository
- Central repository
- Remote Repository
Local repository:
A local repository is a directory on a developer’s computer. This repository includes all versions of the Maven dependencies. Maven would only need to download the dependencies once. They rely on several projects (e.g. ODBC).
Central Repository:
Maven Group is developed as the central Maven repository. Maven searches for any dependencies required in this central repository but can’t be found in your local repository. Maven then downloads to your local repository these dependencies. Via this link you can access the central repository.
Remote repository:
Remote repository is a repository on a web server from which Maven can access dependencies. These are also used to host internal projects. Maven then downloads to your local repository these dependencies.
Benefits of using Maven in Java:
Build tool:
This is a tool which automates the software project. The benefit of automating build projects is to minimize errors occurring during manual building. It creates a JAR, WAR and EAR file in the Java environment. It is faster than a human in performing the task. It is faster because it has a lot of sensible default values.
Dependency management:
This is one of the main benefits of building a Java application is dependency management. Java depends on internal and external libraries with different versions. So it is evident to have an internal maven repository to archive all JAR files.
Transitive dependency:
Maven also helps in managing transitive dependencies. If you are currently working on spring framework, you need not download all libraries of spring framework. Maven will download all the JAR files in supported versions. This eliminates errors like NoClassDefFoundError, UnnsupportedClassVersionError which arise due incorrect libraries.
Take your career to new heights of success with Core Java Training
Pom.xml:
Another important thing about Maven is pom.xml, it’s close to ANT development tool create.xml. You have their pom.xml for each project, which is the Project object model. This pom.xml includes descriptions of the project e.g. ArtifactId, GroupId, name, etc. It is used to create deliverables such as JAR file, these can be used to add JAR to the internal maven repository. Further Java HashSet example, the pom.xml also includes Maven Plugins used to build a JAR file from class files and resources in a project like JAR plug-in. Pom.xml also contains all the dependencies e.g. JAR files provided by your Java project, and their version.
Task V/S goals:
Maven projects can be developed and run either from the command line or from Eclipse. Maven has goals close to task. You can run those goals using the MVN command in the command line to invoke them.
You need to include maven binaries such as MAVEN HOME / bin in your PATH to create. Then run a Maven project from the command line. If you have installed the M2Eclipse plugin, you can conduct clean maven installations directly from Eclipse itself. Two commonly used maven targets are clean and mount.
Target directory:
When creating the project using Maven it creates resource class files and copies in the target directory. All your class files can be found inside the target / classes directory. This directory is cleaned when you run the maven clean command to compile your Java files again and build new class files.
On the other side, the command MVN install runs both Maven clean and create together. The maven clean will clean old build artifacts from the target directory, for example, class files.
Conclusion:
In this article I briefly discussed the use of the Maven tool in Java. It is still the most popular tool in Java. You can learn more about Java through Core java online training. I hope you understood the use of the maven tool in Java. Thank you for reading this article.