Categories
spring-boot

no main manifest attribute, in – spring boot

In this post, we will learn to resolve no main manifest attribute, in – spring boot application

Once your jar is build using maven command, we will attempt to run the jar

This exception will occur if you didn’t add maven build plugin in your pom.xml file

Solution

Add below maven build plugin in your pom.xml

<plugin>
    <groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-maven-plugin</artifactId>
	<executions>
		<execution>
			<goals>
			<goal>repackage</goal>
			</goals>
	    </execution>
	</executions>
</plugin>

After adding above plugin in your pom.xml, Build your spring boot project using maven command mvn clean install

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.3.0.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>demo</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

After adding maven build plugin, you can build and run your spring boot application successfully.

Categories
java maven

Create a Maven Project using command prompt

In this tutorial we will learn to create a maven project using command prompt 

Prerequisites
Syntax
mvn archetype:generate -DgroupId= -DartifactId= -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Sample
mvn archetype:generate -DgroupId=com.beginnergsbug -DartifactId=sample-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
Output

C:\Users\USHA RAJESH\Desktop\sample>mvn archetype:generate -DgroupId=com.beginnergsbug -DartifactId=sample-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Batch mode
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.pom (703 B at 1.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-bundles/2/maven-archetype-bundles-2.pom (1.5 kB at 3.5 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/maven-archetype-parent/1/maven-archetype-parent-1.pom (1.3 kB at 2.9 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.0/maven-archetype-quickstart-1.0.jar (4.3 kB at 7.6 kB/s)
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: basedir, Value: C:\Users\USHA RAJESH\Desktop\sample
[INFO] Parameter: package, Value: com.beginnergsbug
[INFO] Parameter: groupId, Value: com.beginnergsbug
[INFO] Parameter: artifactId, Value: sample-project
[INFO] Parameter: packageName, Value: com.beginnergsbug
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\Users\USHA RAJESH\Desktop\sample\sample-project
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  12.855 s
[INFO] Finished at: 2020-01-31T09:17:42+05:30
[INFO] ------------------------------------------------------------------------

C:\Users\USHA RAJESH\Desktop\sample>     
Syntax Explanation

mvn maven base command

archetype:generate= to generate a maven project

-DgroupId= group id for the project

-DartifactId= artifact id it is similar to project name

-DarchetypeArtifactId= type of archetype

-DinteractiveMode= true/false 

Related Articles

How to install Apache Maven in windows

Categories
java maven

Set Maven Home in Windows

In this tutorial we will learn to set Maven home in windows.

Please refer my previous tutorial to download and install maven.

This is the follow up tutorial of my previous post

Prerequisites

Step 1

Copy Maven installed Path

In my case it is C:\Maven\apache-maven-3.6.3

Apache Maven Home

Step 2

Open My computer 

Step 3

Right click the This PC

Step 4

Click on Properties

Step 5

Click on Advanced system settings

Step 6

Click on the Environment variables

Step 7

Click New on the System variables column

Step 8

Enter Variable name as M2_HOME
Enter Variable value as C:\Maven\apache-maven-3.6.3
click ok
Note :
Variable name should be CAPS
Variable value should be as your maven installed path
don’t copy until bin folder

M2_HOME

Step 9

After Click OK
we can see the M2_HOME variable in environment variables

Step 10

After Click OK
we can see the M2_HOME variable in environment variables

Step 11

Now we need to need to add this JAVA_HOME to Path variable
Search for Path variable in same system variables window

Step 12

After selecting Path variable
Click on Edit button

Step 13

Edit environment variable dialog box will appear
Click on the New button

Step 14

Text box will appear on the list
add %M2_HOME%\bin in the text box

Step 15

Click OK after adding %M2_HOME%\bin
Now close all the windows

Step 16

We can verify by below steps
open the command prompt
type mvn -version

mvn -version

That’s it !! 

Related Articles

Create a Maven Project using command prompt