我在运行通过“mvn package”创建的 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 时
我想知道我是否在这里遗漏了什么?
原文由 J. Zhang 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用 Spring Boot,您不需要 maven-shade-plugin。 Spring Boot 将负责必要的打包。
如果您有多个具有主要方法的类,则可以使用正确的方法配置 spring-boot-maven-plugin:
您可以在 Maven 插件的文档中找到可能的配置列表:http: //docs.spring.io/spring-boot/docs/1.5.3.RELEASE/maven-plugin/repackage-mojo.html