找不到此类问题的原因。我需要阅读我的MANIFEST.MF文件属性,该属性始终为null。 这是我在pom.xml中的maven-jar-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Project>ExternalBettingHistoryService</Project>
<Build>${buildVersion}</Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
这是我读清单的课程:
@Controller
public class StatusController
{
@Autowired
private ServletContext servletContext;
public void readManifest() throws IOException
{
Properties manifest = new Properties();
try (InputStream inputStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF"))
{
manifest.load(inputStream);
}
}
此代码永久导致NullPointerException,因为servletContext.getResourceAsStream(“ / META-INF / MANIFEST.MF”)返回null。
我仅使用mvn包构建项目。这是.jar中的清单文件:[jar] /target/classes/META-INF/MANIFEST.MF。该文件有效且存在,看起来类似于:
Manifest-Version: 1.0
Implementation-Title: sampleTitle
Implementation-Version: 0.0.1-SNAPSHOT
Build: DEV
Built-By: me
Implementation-Vendor-Id: com.sample.project
Project: ProjectName
Created-By: Apache Maven 3.5.0
Build-Jdk: 1.8.0_144
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/parent-pom/projectname
我尝试使用以下项目运行项目:
在两种情况下,servletContext.getResourceAsStream(“ / META-INF / MANIFEST.MF”)的inputStream均为空。
可能是什么问题?