How to manipulate Manifest file with maven

2020-04-14 08:15发布

I have an EAR file built with maven. The EAR contains several jars and I need to add a line in the manifest file for just one of these jars. I know of the maven-jar-plugin option (manifestEntries) but this is good for a single standalone jar, not one that is inside an EAR.

2条回答
萌系小妹纸
2楼-- · 2020-04-14 08:52

If you take a deeper look into maven-ear-plugin configuration you will find the archive configuration part which is exactly intended for such purposes.

This can be added to the configuration of the maven-ear-plugin:

<archive>
  <addMavenDescriptor/>
  <compress/>
  <forced/>
  <index/>
  <manifest>
    <addClasspath/>
    <addDefaultImplementationEntries/>
    <addDefaultSpecificationEntries/>
    <addExtensions/>
    <classpathLayoutType/>
    <classpathMavenRepositoryLayout/>
    <classpathPrefix/>
    <customClasspathLayout/>
    <mainClass/>
    <packageName/>
  </manifest>
  <manifestEntries>
    <key>value</key>
  </manifestEntries>
  <manifestFile/>
  <manifestSections>
    <manifestSection>
      <name/>
      <manifestEntries>
        <key>value</key>
      </manifestEntries>
    <manifestSection/>
  </manifestSections>
  <pomPropertiesFile/>
</archive>

Which gives you any opportunity you need.

查看更多
孤傲高冷的网名
3楼-- · 2020-04-14 08:59

I think can you look at the maven-shade-plugin and use the ManifestResourceTransformer to change the manifest for the jar.

查看更多
登录 后发表回答