运行 spring boot jar 时找不到或加载主类

J. *_*ang 2 java spring maven spring-boot

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

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>
Run Code Online (Sandbox Code Playgroud)

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);
    }        
}
Run Code Online (Sandbox Code Playgroud)

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

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

dun*_*nni 5

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

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

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <mainClass>ves.sfdc.Application</mainClass>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

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