0

cannot find the reason of such problem. I need to read my MANIFEST.MF file properties and it is always null. This is my maven-jar-plugin in pom.xml:

        <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>

Here is a class where I read manifest:

@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);
        }
}

This code permanently causes NullPointerException because servletContext.getResourceAsStream("/META-INF/MANIFEST.MF") returns null.

I build project simply using mvn package. The is a manifest file inside .jar: [jar]/target/classes/META-INF/MANIFEST.MF. This file is valid and exists and looks similar to:

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

I tried to run project using:

  • spring-boot:run
  • java -jar target/my-jar.jar

In both cases inputStream of servletContext.getResourceAsStream("/META-INF/MANIFEST.MF") is null.

What may be wrong?

Sviatlana
  • 1,728
  • 6
  • 27
  • 55
  • Why do you need to load the MANIFEST.MF? That is generally something you shouldn't be doing, next to that it might not be a valid `Properties` representation. – M. Deinum Dec 05 '18 at 09:39
  • @Arnaud META-INF/MANIFEST.MF without slash returns first found manifest, i.e. manifest of spring-boot-autoconfiguration, but not my own.. – Sviatlana Dec 05 '18 at 09:42
  • See if this question helps : https://stackoverflow.com/questions/32293962/how-to-read-my-meta-inf-manifest-mf-file-in-a-spring-boot-app – Arnaud Dec 05 '18 at 09:43
  • @Arnaud thank you, but none helped... – Sviatlana Dec 05 '18 at 10:16

0 Answers0