2016-07-01 34 views
0

我需要你的幫助。我必須編寫一個腳本,在Maven構建應用程序期間將文件的子版本添加到MANIFEST.MF文件中。Maven在構建MANIFEST.MF文件時添加我自己的信息

我寫了一些Mojo類,獲取我需要的信息(我將它命名爲GenerateVersionPropertyFile.class)。現在我需要知道如何將這些信息放到清單文件中。

這裏是我的pom.xml

<build> 
    <finalName>${project.artifactId}</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ejb-plugin</artifactId> 
      <configuration> 
       <ejbVersion>3.1</ejbVersion> 
       <generateClient>true</generateClient> 
       <archive> 
        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> 
        <!-- 
        <manifest> 
         <addClasspath>true</addClasspath> 
         <classpathPrefix>lib</classpathPrefix> 
        </manifest> 
        --> 
        <manifestEntries> 
         <Built-By /> 
        </manifestEntries> 
        <manifestSections> 
         <manifestSection> 
          <Name>appName</Name> 
          <manifestEntries> 
           <Implementation-Title>${project.name}</Implementation-Title> 
           <Implementation-Version>${project.version}</Implementation-Version> 
           <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id> 
           <Implementation-Vendor>${project.organization.name}</Implementation-Vendor> 
          </manifestEntries> 
         </manifestSection> 
         <manifestSection> 
          <Name>exampleApp</Name> 
          <manifestEntries> 
           <Implementation-Title>exampleEntry</Implementation-Title> 
           <Implementation-Version>dupa2</Implementation-Version> 
           <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id> 
           <Implementation-Vendor>${project.organization.name}</Implementation-Vendor> 
          </manifestEntries> 
         </manifestSection> 
        </manifestSections> 
       </archive> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.1.1</version> 
      <executions> 
      <execution> 
      <phase>test</phase> 
      <goals> 
       <goal>java</goal> 
      </goals> 
      <configuration> 
       <mainClass>maven.GenerateVersionPropertyFile</mainClass> 
       <arguments> 
       <argument>${project.basedir}\src</argument> 
       <argument>${project.build.directory}</argument> 
       </arguments> 
      </configuration> 
      </execution> 
      </executions> 
      </plugin> 
    </plugins> 
</build> 

<profiles> 
    <profile> 
     <id>server-ejb-build-devel</id> 
     <activation> 
      <property> 
       <name>build-devel</name> 
      </property> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-ejb-plugin</artifactId> 
        <configuration> 
         <archive> 
          <manifestSections> 
           <manifestSection> 
            <Name>app1</Name> 
            <manifestEntries> 
             <Implementation-Build>${buildNumber}</Implementation-Build> 
             <Implementation-Timestamp>${timestamp}</Implementation-Timestamp> 
            </manifestEntries> 
           </manifestSection> 
          </manifestSections> 
         </archive> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 
+0

你爲什麼要使用Java類,而不是直接從子模塊POM版本標籤怎麼做呢? – Apostolos

+0

不好意思,我說錯了。當我說子項目時,我會考慮項目中的json模式。我需要解析這些文件並從中獲取信息,所以我使用了Java類。 – user2420602

+0

嗯任何移動gradle的機會?它對於這樣的事情是非常強大的。只是一個想法 – Apostolos

回答

0

不得不使用maven-JAR-插件在你的POM。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.4</version> 
    <configuration> 
    <archive> 
     <manifest> 
     <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
     <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> 
     </manifest> 
     <manifestEntries> 
     <key>value</key> 
     </manifestEntries> 
    </archive> 
</configuration> 
</plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ejb-plugin</artifactId> 
      <version>${maven-ejb-plugin.version}</version> 
      <configuration> 
       <ejbVersion>3.1</ejbVersion> 
      </configuration> 
     </plugin> 
相關問題