0% found this document useful (0 votes)
6 views2 pages

Devops prgm4

This document outlines the steps to create a Maven project using a specified archetype and configure it with a sample Java application. It includes instructions for setting up the POM file with dependencies, creating a simple Java class, and running the project using Maven and Gradle. The document provides detailed code snippets for both the POM file and the Java application to facilitate the setup process.

Uploaded by

rakshithatl141
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Devops prgm4

This document outlines the steps to create a Maven project using a specified archetype and configure it with a sample Java application. It includes instructions for setting up the POM file with dependencies, creating a simple Java class, and running the project using Maven and Gradle. The document provides detailed code snippets for both the POM file and the Java application to facilitate the setup process.

Uploaded by

rakshithatl141
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

____________________________program 4______________________________

step1:-create maven project

mvn archetype:generate -DgroupId=com.example -DartifactId=maven-example -


DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

step2:change directory to artifactid what we have given and


open pom.xml file

copy paste below program

<?xml version="1.0" encoding="UTF-8"?>


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>maven-example</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<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>
</project>

step3: 1.open java code app.java file inside


src/main/java/com/example/
2.open app.java copy below code and paste it to app.java

package com.example;
public class App {
public static void main(String[] args) {
System.out.println("Hello, Maven");
System.out.println("This is the simple realworld example....");

int a = 5;
int b = 10;
System.out.println("Sum of " + a + " and " + b + " is " + sum(a, b));
}

public static int sum(int x, int y) {


return x + y;
}
}

step4:-run project
1.mvn clean install
2.mvn exec:java -Dexec.mainClass="com.example.App"
3.gradle init---gradle merger
open build.gradle copy paste below content

plugins {
id 'java'
}

group = 'com.example'
version = '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

dependencies {
testImplementation 'junit:junit:4.12'
}

task run(type: JavaExec) {


main = 'com.example.App'
classpath = sourceSets.main.runtimeClasspath
}

step5:run project
1.gradlew build or gradle build
2.gradlew run or gradle run

You might also like