![]() |
An Apache Maven artifact is a file, typically a JAR (Java Archive), created when a project is built. Each artifact is uniquely identified by three main coordinates: groupId, artifactId, and version. Maven artifacts are package units of your software. When building a project, Maven uses these artifacts to manage dependencies, plugins, and libraries. An artifact can be a library, module, framework, or any other package that a project requires. These artifacts are stored in repositories, either local, central, or remote, and are retrieved and used as needed by Maven during the build process.
Tools and Technologies
ExampleSetting Up a Maven ProjectStep 1: Create a New Maven ProjectCreate a new Maven project using the below Maven command. mvn archetype:generate -DgroupId=com.example.myapp -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false Directory Structure: Maven creates a standard directory structure: my-app/
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── example
│ └── myapp
│ └── App.java
└── test
└── java
└── com
└── example
└── myapp
└── AppTest.java
Step 2: Add DependenciesDependencies are specified in the pom.xml file. For instance, to add the JUnit library for testing, you would add the following dependency. <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
Step 3: Configuring PluginsPlugins are added similarly to dependencies in the pom.xml file. For example, to use the Maven Compiler Plugin, you would add. <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build> Example pom.xml File:Here’s a complete example of a pom.xml file for a basic Maven project.
Common Maven CommandsClean Project:This command removes all the files that are generated by the previous build. mvn clean Output:![]()
|
Reffered: https://www.geeksforgeeks.org
Advance Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |