【发布时间】:2015-03-19 19:03:43
【问题描述】:
Maven 构建成功,但是当我尝试运行它时失败:
Error: Could not find or load main class app.jar
我在resources/META-INF/MANIFEST.MF 有
Manifest-Version: 1.0
Main-Class: go.Application
一切似乎都已到位。怎么了?
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
更新1
使用 IntelliJ 构建 jar 工件时也是如此。
更新2
好的,我设法运行它,但现在我有:
Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
UPDATE3
通过添加到 Application.java 使其工作:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
return factory;
}
【问题讨论】:
-
如何启动应用程序?在我看来,调用 java 时参数
-jar丢失了。 -
当我添加
-jar它显示不同的错误Unable to access jarfile -
听起来你的路径是错误的。您在正确的目录中吗?
-
这是春靴吗?使用 spring-boot 你不需要那个 maven jar 配置,也不需要你在 application.java 中创建的 bean。
-
我和工程师 Dollery 有同样的问题。似乎您正试图将其作为 Spring Boot 应用程序运行。如果是这样,那么您需要 spring-boot-maven-plugin 并在您的 jar 中设置所有必需的引用。那么 Spring Boot 呢?
标签: java spring maven jar manifest