运行 spring boot jar 时找不到或加载主类 [英] Could not find or load main class, when running spring boot jar

查看:158
本文介绍了运行 spring boot jar 时找不到或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行通过mvn 包"创建的 jar 时遇到问题.我尝试了各种解决方案,但都没有成功.

I Have issues running a jar that was created through 'mvn package'. I tried various solutions with no success.

pom.xml

<groupId>org.springframework</groupId>
<artifactId>rest-service</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.4.RELEASE</version>
</parent>
...
<properties>
  <java.version>1.8</java.version>
  <start-class>ves.sfdc.Application</start-class>
</properties>


<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

projectroot\src\main\java\ves\sfdc\application.java

projectroot\src\main\java\ves\sfdc\application.java

@SpringBootApplication
@Configuration
@ComponentScan
@EnableAsync
@EnableScheduling
@EnableAutoConfiguration

public class Application{

    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    AccountService accountService;
    @Autowired
    static
    SfdcUtil sfdcUtil= new SfdcUtil();
    @Autowired
    NamedParameterJdbcTemplate jdbcTemplate2;    

    public static void main(String[] args) throws SecurityException, IOException {   
        SpringApplication.run(Application.class, args);
    }        
}

这个项目在 Eclipse 中运行良好,当我执行 mvn spring-boot:run

This project works fine in Eclipse, and when I do mvn spring-boot:run

我想知道我是否在这里遗漏了什么?

I Wonder if I'm missing something here?

推荐答案

使用 Spring Boot,您不需要 maven-shade-plugin.Spring Boot 将负责必要的包装.

With Spring Boot you don't need the maven-shade-plugin. Spring Boot will take care of the necessary packaging.

如果你有多个带有main方法的类,你可以用正确的一个来配置spring-boot-maven-plugin:

If you have multiple classes with main methods, you can configure the spring-boot-maven-plugin with the correct one:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <mainClass>ves.sfdc.Application</mainClass>
  </configuration>
</plugin>

您可以在 maven 插件的文档中找到可能的配置列表:http://docs.spring.io/spring-boot/docs/1.5.3.RELEASE/maven-plugin/repackage-mojo.html

You can find a list of possible configurations in the documentation of the maven plugin: http://docs.spring.io/spring-boot/docs/1.5.3.RELEASE/maven-plugin/repackage-mojo.html

这篇关于运行 spring boot jar 时找不到或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆