0

I have a spring boot application which I am trying to run from command line on my Mac but I get following error:

Error: Could not find or load main class MyProject.jar

Here is my pom.xml

<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/maven-v4_0_0.xsd">


    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myproject.abc</groupId>
    <artifactId>MyProject</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
    </parent>

    <properties>
        <start-class>com.myproject.abc.MyMain</start-class>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

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

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
        </dependency>

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

        <dependency>
            <groupId>com.google.collections</groupId>
            <artifactId>google-collections</artifactId>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/MyProject-1.0.0.lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                    <archive>
                        <manifest>
                            <mainClass>com.myproject.abc.MyMain</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>
    </build>


</project>

I have referred various posts online and as visible from above pom.xml, have tried adding <start-class>, spring-boot-maven-plugin, but nothing worked.

On further searching found following link Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher, I removed M2_HOME from .bash_profile which looked as below

export M2_HOME=/Users/myuser/Downloads/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin

Then I installed maven using brew -> deleted the .m2 folder -> ran mvn clean install-> run java MyProject.jar

Still facing same issue. Any ideas?

Manas Saxena
  • 2,171
  • 6
  • 39
  • 58

0 Answers0