1

After i finished my spring-boot server i want to make it a jar so i can deploy it on a remote server. I choose to do this with maven

After .jar-with-dependecies.jar is created i upload it on server and try to run

java -jar buyme-0.0.1-SNAPSHOT-jar-with-dependencies.jar

Like everybody else i get

Error: Could not find or load main class com.buyme.BuymeApplication

I tried answers from here:

Link 1

Link 2

Link 3

Link 4

Nothing seems to work. This is my

pom.xml

<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                       <mainClass>com.buyme.BuymeApplication</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Manifest

Manifest-Version: 1.0
Main-Class: com.buyme.BuymeApplication

This is the project structure

enter image description here

mvn commands:

mvnc clean install (sometimes i tried assembly:assembly with the other two)

This doesn't work either:

java -cp <name>.jar com.buyme.BuymeApplication
ALex
  • 673
  • 1
  • 6
  • 19

1 Answers1

1

I managed to solve it :

I used this answer:

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.2.RELEASE</version>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
</build>
ALex
  • 673
  • 1
  • 6
  • 19