12

Standard way - using maven-jar-plugin - generates manifest file only during package phase and directly into jar file.

What I need is to generate manifest during compile phase and to be available in <target>/classes/META-INF.

My goal is to be able to read this manifest file in project running in debug mode in IntelliJ Idea. (Idea resolves in-project jar dependencies from <target>/classes instead of from <target>/*.jar - for hot-swap purpose).

The only solution I know of so far is to actually create my own MANIFEST.MF in src/main/java/resources/META-INF and let it be filtered+copied during resources phase. But I want to avoid this solution, I want the manifest to be generated standard way using <archive> configuration in pom file.

4
  • I don't think there is a plugin to do that directly. A contrived way would be to bind an execution of maven-jar-plugin to compile, unpack the jar and copy the MANIFEST... A more direct solution would be to create a custom plugin using Maven Archiver.
    – Tunaki
    Commented Jan 8, 2016 at 10:37
  • Hi Petr, did you find a solution for this?
    – fmilani
    Commented Aug 14, 2017 at 23:34
  • @fmilani this is kinda old question and I have forgotten about it :) Have you tried the @frekele's answer below? If it does not work I could make a proposition / push request to maven-jar-plugin on github, if the project is there and the repo owner is active. Or make a custom plugin as @Tunaki suggests. Commented Aug 15, 2017 at 0:01
  • I've tried @frekele's answer and it didn't generate target/Project-version/META-INF/MANIFEST.MF as needed to try debugging a project in Netbeans where it runs from that location instead of from the WAR file. I'm looking for an option to create the manifest there during build instead of in .war during package.
    – jla
    Commented Jun 19, 2019 at 21:05

2 Answers 2

4

You can do this with maven-bundle-plugin.

   <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>3.3.0</version>
        <executions>
            <execution>
                <id>bundle-manifest</id>
                <phase>process-classes</phase>
                <goals>
                    <goal>manifest</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <archive>
                <index>true</index>
                <manifest>
                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                </manifest>
                <manifestEntries>
                    <Implementation-URL>${project.url}</Implementation-URL>
                    <Java-Version>${java.version}</Java-Version>
                    <Java-Vendor>${java.vendor}</Java-Vendor>
                    <Os-Name>${os.name}</Os-Name>
                    <Os-Arch>${os.arch}</Os-Arch>
                    <Os-Version>${os.version}</Os-Version>
                    <Scm-Url>${project.scm.url}</Scm-Url>
                    <Scm-Connection>${project.scm.connection}</Scm-Connection>
                </manifestEntries>
            </archive>
        </configuration>
    </plugin>
1
  • This isn't generating a MANIFEST.MF in target/Project-version/META-INF/ like a similar archive/manifestEntries block in maven-war-plugin is doing during package to target/Project-verssion.war
    – jla
    Commented Jun 19, 2019 at 21:03
0

Many thanks for the excellent answer from @frekele. As I cannot add comments to existing answers, so adding this one to note that you need to tie to the compile phase instead of process-classes if you want to generate the manifest during the compile phase:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>4.2.1</version>
    <executions>
        <execution>
        <id>bundle-manifest</id>
        <phase>compile</phase>
        <!-- ... -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.