繁体   English   中英

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

[英]Could not find or load main class, when running spring boot jar

我在运行通过“ 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>

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

我想知道我是否想念这里吗?

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

如果您有多个使用主要方法的类,则可以使用正确的方法配置spring-boot-maven-plugin:

<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

在这种情况下,问题出在maven上。 您下载的依赖项没有所需的版本。 一些依赖项可以相互大量使用,有时它们仅与其他jar的特定版本匹配。

 Solution:- It will take some time but clear .m2 and rebuild maven to download all dependencies again. or you are having two version of same dependencies. So check all maven jars and remove jars having common names. 

就我而言,这是不正确/不正确的依赖关系。 标记中发现>问题突出显示.pom无效的存档。

compile group: 'org.apache.httpcomponents', name: 'httpcomponents-client', version: '4.5.6', ext: 'pom'

更改为

    `compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'`

暂无
暂无

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

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