How to write in the manifest file?

My manifest file is not updated, I used the maven-war-plugin to write, but nothing happened if I changed the name of the manifest file directory, I get a manifest file not found error message during packaging, but when I put it in the right one place, nothing happens, the contents of the file does not change.

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <archive> <addMavenDescriptor/> <compress/> <forced/> <index/> <manifest> <addClasspath/> <addDefaultImplementationEntries/> <addDefaultSpecificationEntries/> <addExtensions/> <classpathLayoutType/> <classpathMavenRepositoryLayout/> <classpathPrefix/> <customClasspathLayout/> <mainClass/> <packageName/> </manifest> <manifestEntries> <key>value</key> </manifestEntries> <manifestFile>src/main/webapp/META-INF/test/MANIFEST.MF</manifestFile> <pomPropertiesFile/> </archive> </configuration> </plugin> 

and the contents of my manifest file:

  Manifest-Version: 1.0 

Any idea why it doesn't work and how can this be done correctly?

0
java maven manifest
source share
2 answers

Do not use an empty tag. You must set the boolean parameter to true:

  <manifest> <addClasspath>true</addClasspath> </manifest> 

See official white paper

+1
source share

whole solution:

add the maven war plugin or another plugin that supports the archive tag inside its configuration to the pom.xml file:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> </manifest> <manifestEntries> <Build-Time>${maven.build.timestamp}</Build-Time> <Build-Host>${agent.name}</Build-Host> <Build-User>${user.name}</Build-User> <Build-Maven>Maven ${maven.version}</Build-Maven> <Build-Java>${java.version}</Build-Java> <Build-OS>${os.name}</Build-OS> <Build-Label>${project.version}</Build-Label> <Build-Path>${basedir}</Build-Path> </manifestEntries> <manifestFile>src/main/webapp/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> </plugin> 

we can specify the build time format by adding tag properties for the pom configuration:

 <properties> <maven.build.timestamp.format>dd/MM/yyyy</maven.build.timestamp.format> </properties> 

these properties are recorded automatically in the manifest file inside the war after each assembly:

  Manifest-Version: 1.0 Build-Time: 15/09/2014 Build-Java: 1.7.0_60 Class-Path: commons-codec-1.9.jar javax.mail-1.5.0.jar activation-1.1.jar joda-time-2.3.jar spring-ldap -core-2.0.1.RELEASE.jar spring-data-commons-1.6.1.RELEASE.jar jcl-ove r-slf4j-1.7.1.jar Built-By: aXSEDZ Created-By: Apache Maven Build-Host: Build-Path: C:\WSLocal\5portal\5portalweb Build-OS: Windows 7 Build-Jdk: 1.7.0_60 Build-Maven: Maven null Build-Label: 0.0.5-SNAPSHOT Build-User: aXSEDZ Archiver-Version: Plexus Archiver 

After that, read the file as a resource file, in my case I get access to it: spring context:

  Properties props = new Properties(); try { WebApplicationContext webAppContext = ContextLoaderListener.getCurrentWebApplicationContext(); if (webAppContext != null) { InputStream inputStream = webAppContext.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"); props.load(inputStream); } } catch (IOException e) { } 
0
source share

All Articles