简体   繁体   English

执行从Maven构建创建的jar文件

[英]executing jar file created from maven build

I have created a jar file through mvn clean install. 我已经通过mvn clean install创建了一个jar文件。 In pom.xml I specified the name of main class as well. 在pom.xml中,我还指定了主类的名称。

 <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. 当我尝试使用java -jar app.jar执行jar时,它给我错误,提示在app.jar中没有主清单属性,并且当我使用此命令java -cp app.jar com指定主类名称时,也会出现错误。 dashboard.report.MainClass,它为javax / mail / MessagingException提供了我的NoClassDefError。

PS: If I execute the code from eclipse, it works fine without any issue PS:如果我从eclipse执行代码,则可以正常工作而不会出现任何问题

you can use spring-boot plugin to create a fat jar with dependencies. 您可以使用spring-boot插件创建具有依赖项的胖jar。 Add this to your pom.xml 将此添加到您的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 . 现在,当您执行mvn clean install it will create 2 jars one with -spring-boot is what you should execute. 它将创建2个jar,其中一个应该使用-spring-boot执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM