Maven is an Apache Software Foundation build tool for project management that automates Java projects

There is Gradle, which is similar to Maven, but the uses are a little bit different. 

Maven is for spring projects, while Gradle is for android projects. However, both deal with the springboot projects.

 

Let us make our first Maven project together. It will be useful for your better understanding.

Creating a new maven project is very similar to other projects like dynamic web projects we have done so far. 

There is a small different part: you need to choose an Internal Catalog and the last Artifact Id. 

maven-archetype-webapp is for web development, so for our next project, we are choosing this. Depending on the artifact id, you will see the different structures.

Next, you must write the domain reversely, and the artifact id will be your project's name. 


If there is an error that you can see(the red X sign), you can erase that by adding
Apache Tomcat v9.0.

Then, it's solved! 

 

As you can see, the project's structure is different from the dynamic web project.

This maven project is similar to the spring projects we will discuss next time. Let's take a deep look at the maven project.

The Java Resources contain controller, service, DTO, and DAO classes. In the webapp folder in the Deployed Resources folder, there are view pages. 

pom.xml is the configuration file of Maven. 

In this file, we will save the dependencies. 

Let's add cos library in it.

1. Maven Repository: Search/Browse/Explore (mvnrepository.com) Click the link.

2. Search cos and click the second one. 

3.Click 05 Nov 2002.

4. Copy the maven dependency tags and paste into the pom.xml file. 

5. When you save the file, it will download the library to the local repository.

To check your local repository, click window-Preferences- Maven - User Settings.

Now, we will add the Oracle repository

As it is better for fewer issues, we will first add <repository> tag which is an unofficial code. If you encounter any issue with downloading Oracle, try to download this repository. 

<repositories>
<repository>
<id>codelds</id>
<url>https://code.lds.org/nexus/content/groups/main-repo</url>
</repository>
</repositories>

And, we will add Oracle JDBC Library in the <dependencies> tag. 

<!-- Oracle JDBC Library -->
		<dependency>
			<groupId>com.oracle</groupId>
			<artifactId>ojdbc6</artifactId>
			<version>11.2.0.3</version>
		</dependency>

To add MySQL repository, follow this : 

1. Maven Repository: Search/Browse/Explore (mvnrepository.com) enter MVN repository

2. Download the MySQL Connector/J (J means Java).

3. Download the same version of what you have on your system.

Since I have the 8.0.28 version, I will download this. 

4. Copy and paste the tags in the pom.xml file. 

To add MyBatis or other repositories, you will do the same. 

This is how you manage libraries.

 

To export and import the maven projects is also different from how we did before. Exporting and importing it as a WAR file will be saved as a dynamic web project. To export the Maven project, you will copy the whole project and paste it to the place you want. This is different from exporting the dynamic web project, but it is easier because you don't need any skills to do this. To import, click Existing Projects into Workspace in the General menu.

 

+ Recent posts