0

I am trying to create an executable .jar file for an application, but when I run "java -jar myapp.jar" I get the error:

Error: Could not find or load main class com.vaadin.app.MainView

I have added the mainClass argument in my pom.xml, and the Manifest.mf shows this:

Manifest-Version: 1.0

Build-Jdk-Spec: 1.8

Created-By: Maven Archiver 3.4.0

Main-Class: com.vaadin.app.MainView

Is there a reason why it can't find the Main() meathod in my class MainView?

Community
  • 1
  • 1
2EricH
  • 42
  • 8

2 Answers2

0

I faced the same issues and for me, the jar file was not properly built. You can create jar file by going to Run configuration(right-click in eclipse--> maven -->build) and in goals write

clean package -Dmaven.test.skip=true

This will generate your proper jar and this you can run using java -jar myapp.jar

Prakhar
  • 15
  • 3
0

The problem was in my pom file, it needed the maven-assembly-plugin added with the following configuration:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>
                                        com.vaadin.app.MainView
                                    </mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

Then running the jar-with-dependencies.jar exits with code 0.

2EricH
  • 42
  • 8