How to write in the manifest file?

三世轮回 提交于 2019-12-12 04:47:04

问题


My manifest file is not updated, I used the plugin maven-war-plugin to write, but nothing happened, if I change the name of the directory of the manifest file I get an error manifest file not found while packaging , but when I put it in the right place nothing happens, the content of the file is unchanged.

<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 content of my manifest file is:

    Manifest-Version: 1.0

Any idea, why it doesn't work or how it can be done correctly?


回答1:


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

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

See the official doc




回答2:


the whole solution :

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

        <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 format of the build time also by adding the tag properties for the pom configuration :

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

those properties are written automatically in the Manifest file inside the war after each build :

    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 access it throw a 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) {

    }           


来源:https://stackoverflow.com/questions/25245021/how-to-write-in-the-manifest-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!