executing jar file created from maven build

I have created a jar file through mvn clean install. In pom.xml I specified the name of main class as well.

 <configuration>
    <archive>
        <manifest>
            <mainClass>com.amdocs.som.dashboard.report.MainClass</mainClass>
        </manifest>
    </archive>
 </configuration>

When I try to execute the jar with java -jar app.jar, it gives me error saying no main manifest attribute, in app.jar and when I specify the main class name as well with this command java -cp app.jar com.dashboard.report.MainClass, it gives my NoClassDefError for javax/mail/MessagingException.

PS: If I execute the code from eclipse, it works fine without any issue


you can use spring-boot plugin to create a fat jar with dependencies. Add this to your pom.xml

<build>
    <plugins>
     .... other 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>
                <configuration>
                    <classifier>spring-boot</classifier>
                    <mainClass>com.amdocs.som.dashboard.report.MainClass</mainClass>
                                <executable>true</executable>
                </configuration>
            </execution>
        </executions>
    </plugin>
  </build>
</plugins>

Now when you do a mvn clean install . it will create 2 jars one with -spring-boot is what you should execute.

链接地址: http://www.djcxy.com/p/55026.html

上一篇: 如何使用新的Android Multidex支持库启用多重分化

下一篇: 执行从maven build创建的jar文件