簡體   English   中英

如何在清單文件中寫入?

[英]How to write in the manifest file?

我的清單文件未更新,我使用插件maven-war-plugin編寫,但是什么也沒有發生,如果我更改清單文件的目錄名稱,則會得到一個錯誤的manifest file not found ,該清單文件在包裝時manifest file not found ,但是當我放入時它在正確的地方什么也沒有發生,文件的內容不變。

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

我的清單文件的內容是:

    Manifest-Version: 1.0

任何想法,為什么它不起作用或如何正確完成?

不要使用空標簽。 您應該將boolean參數設置為true:

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

官方文件

整個解決方案:

將maven war插件或另一個在其配置中支持archive標記的插件添加到pom.xml文件中:

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

我們還可以通過為pom配置添加標簽屬性來指定構建時間的格式:

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

這些屬性會在每次構建后自動寫入戰爭中的清單文件中:

    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

之后,將該文件作為資源文件讀取,以我為例,我訪問它時將拋出spring上下文:

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

    }           

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM