0

Basically, I want to generate a jar file named <project.name>.jar in addition to default jar file(which in my case is something like <project.name> + <project.version>.jar). NOTICE : This <project.name>.jar is all the same to default jar but the name.

And this additional jar should have a manifest file like below which is the manifest file of default generated jar

anifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: XXX
Start-Class: com.XXXX.XXX.Application
Spring-Boot-Version: 1.3.1.RELEASE
Created-By: Apache Maven
Build-Jdk: 1.8.0_74
Main-Class: org.springframework.boot.loader.JarLauncher

I am adding additional block in my as follows

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                 ....

                <execution>
                    <id>copy-jar</id>
                    <phase>package</phase>
                    <goals><goal>jar</goal></goals>
                    <configuration>
                        <finalName>${project.name}</finalName>
                    </configuration>
                </execution>
            <execution>
         </plugin>

But in my case, the manifest file generated in my addition jar don't have following impart fields:

Start-Class
Main-Class 
...

So it couldn't be deployed. I know the requirement sounds weird, but the question is clear, how to make maven generate a jar which having a correct and complete manifest file for deployment?

//The complete plugin part

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <goals><goal>test-jar</goal></goals>
                </execution>
                <execution>
                    <id>copy-jar</id>
                    <phase>package</phase>
                    <goals><goal>jar</goal></goals>
                    <configuration>
                        <finalName>${project.artifactId}</finalName>
                    </configuration>
                </execution>
                <execution>
                    <id>dto-jar</id>
                    <goals><goal>jar</goal></goals>
                    <phase>package</phase>
                    <configuration>
                        <finalName>${project.artifactId}-dto</finalName>
                        <includes>
                            <include>**/dto/*</include>
                            <include>**/dto</include>
                            <include>**/exceptions/*</include>
                            <include>**/exceptions</include>
                            <include>**/utils/*</include>
                            <include>**/utils</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Acton
  • 255
  • 4
  • 13
  • 1
    the manifest entries above where configured within the other execution section, right? there is no plugin configuration section outside of the executions section? To be more clear: can you share the whole jar plugin section? – A_Di-Matteo Apr 26 '16 at 20:48
  • @A.DiMatteo Hey, I have added whole jar plugin. I suppose I am using default manifest setting. – Acton Apr 26 '16 at 21:48

2 Answers2

0

Concerning your maven-jar-plugin section:

  • You are having three executions: one for the test-jar goal, two for the jar goal
  • one of them re-using the default execution id (default-jar) to specify the finalName entry, but not specifying any manifest configuration. According to this configuration, your manifest file should also be empty then, not coherent with the description provided by your question then.
  • the additional jar goal execution has a further configuration with customizated option, nothing wrong here, except that you except to have a properly filled manifest file as part of it, while (again) there is no configuration for it.

A possible explanation would be that your pom also provides a pluginManagement section, with further configuration for the maven-jar-plugin, or a parent pom at its top which would then specify a further configuration for the same.

To double check this, you could run

mvn help:effective-pom -Doutput=eff-pom.xml

And check the content of the generated eff-pom.xml file. That would be the single source of truth for your case.


Looking at your manifest entry:

 Spring-Boot-Version: 1.3.1.RELEASE   
 Main-Class: org.springframework.boot.loader.JarLauncher

It makes quite clear that you are working on a Spring Boot project, normally having a Spring Boot parent pom which already configures the required manifest file. However, it makes use of a fat-jar (jar with dependencies or uber jar), not built via the maven-jar-plugin but via the maven-assembly-plugin.

As an example:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/jar-with-dependencies.xml</descriptor>
        </descriptors>
        <archive>
            <manifest>
                <mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
            </manifest>
            <manifestEntries>
                <Start-Class>org.springframework.boot.load.it.jar.EmbeddedJarStarter</Start-Class>
            </manifestEntries>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>jar-with-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Hence you should not look at the Jar Plugin solution, but rather add a further Assembly Plugin execution for the same.

Community
  • 1
  • 1
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • I kind of give up original plan, instead of having two jars(two names) for main jar, I just only keep the default one so it has a correct manifest file by default. But still your suggestions is good to read. thank you – Acton Apr 29 '16 at 15:26
0

Just quick share of some other aspects of this problem. actually pom file should never be in charge of deployment business(even though It could, but very likely bring into more issues in the future). This part should be fully managed by bamboo deploy script. That is what I eventually did.

Acton
  • 255
  • 4
  • 13