1

I did not want to ask this question but I tried all the possible solutions on the StackOverFlow. With all the codes I tried the problem was:

enter image description here

Here is my pom.xml:

<?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.6.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ahmetbesli</groupId>
    <artifactId>nobet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>nobetci</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.12</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20190722</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

I am trying to create the jar file with Intellij build artifacts.

I tried to add maven plugin for creating jar file. I tried to define the mainClass also. But it didn't work.

spring-boot Maven: How to create executable jar with main class?

Create Jar of maven spring boot project

Build jar and run spring boot from cmd

Thanks for your help.

Ahmet Aziz Beşli
  • 1,280
  • 3
  • 19
  • 38

1 Answers1

5

You should NOT use task jar in IntelliJ like that: enter image description here

Instead, we can build jar by this command: ./mvnw clean package

And start service as usual: java -jar demo-0.0.1-SNAPSHOT.jar

Update: Also can use package in IntelliJ: enter image description here

MIN
  • 121
  • 4
  • 1
    which command can also be executed from within IntelliJ by using the package command from the lifecycle options. – jwenting Apr 17 '22 at 04:17