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
7
  • Is that a full pom.xml? How come I only see the plug-in part?
    – Minh Kieu
    Jun 5, 2017 at 13:10
  • As @MinhKieu mentioned, your pom.xml is lacking. Shouldn't you add your dependencies there too?
    – Ishnark
    Jun 5, 2017 at 13:10
  • @Ishnark - That was what he added above, line #4 and it doesn't work
    – Minh Kieu
    Jun 5, 2017 at 13:11
  • Awkward, thanks for pointing that out
    – Ishnark
    Jun 5, 2017 at 13:12
  • I have too many dependencies so it would be pointless to add them here :) i just added what is important.
    – ALex
    Jun 5, 2017 at 13:13

1 Answer 1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.