我需要你的帮助。我必须在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 :(得分:0)
必须在你的pom上使用maven-jar-plugin。
实施例
<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>
答案 1 :(得分:0)
确保,如果要在MANIFAST.MF文件中添加自定义属性,那么构建包是JAR / WAR。
如果在您的pom.xml文件中打包JAR,请使用
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<mode>development</mode>
<url>http://testing/</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
OR 如果在pom.xml文件中打包WAR,请使用
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<mode>development</mode>
<url>http://testing/</url>
</manifestEntries>
</archive>
</configuration>
</plugin>