Spring Boot jar - META-INF inside BOOT-INF folder - spring-boot

Is there any way to have META-INF folder inside BOOT-INF in spring boot packaging jar?
This might be a trivial question, but not sure how to do it. Below is the way i am packaging right now which created three folders BOOT_INF, META_INF, ORG. The reason of asking this is because runnable jar is not able to locate a folder which is inside META-INF.
<build>
<finalName>XYZ</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>XYZ</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>XYZ</exclude>
<exclude>XYZ</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>XYZ</mainClass>
<addResources>true</addResources>
<wait>1000</wait>
<maxAttempts>250</maxAttempts>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>XYZ</version>
<configuration>
<tarLongFileMode>XYZ</tarLongFileMode>
<tarLongFileMode>XYZ</tarLongFileMode>
<descriptors>
<descriptor>XYZ</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>XYZ</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help which plugin i can use in order to do that?

Similar issue resolved in my case after adding META-INF folder under resources.

Related

Configuration inheritance regarding the Maven Shade Plugin

Currently I have problems with the configuration inheritance of the Maven Shade Plugin, what I mean by this is that artifactSet and all configuration options "underneath" it turn red whenever I remove the phase and goals options (which are meant to be inherited from the parents pluginManagement section.
I'll show what I have in my parent first and after that what I'm trying to accomplish.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
<plugin>
</plugins>
</pluginManagement>
</build>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<configuration>
<artifactSet>
<includes>
<include>...</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
<plugin>
</plugins>
</pluginManagement>
</build>
1 - You are missing a type <execution> here -
Change
<executions>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</executions>
to
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
2 - To inherit the configuration from the parent pom.xml, you need to make sure the child pom doesn't define the plugin again within <pluginManagement>. You can remove the tag to inherit the configuration from the parent.

How to remove a a specific directory from the Maven's target directory at the end of the build?

I have a task to unpack all the jars mentioned in the pom.xml and then jar the unpacked content into one single jar. I am able to do this using the unpack-dependency goal of the dependency plugin and the jar plugin.
However, after i generate the new jar, I want to delete the folder that was created after unpacking. I am using the following code snippet in my pom.xml(Please read the comments above each plugin).
<build>
<plugins>
<!-- This part of the code is used to unpack all the dependencies mentioned in my pom.xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includes>**/*.class</includes>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<!-- This part of the code is used for creating a jar with all the contents of the "alternateLocation" directory above -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.directory}/alternateLocation</classesDirectory>
<outputDirectory>${project.build.directory}</outputDirectory>
<finalName>abc</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!-- I am using this part of the code to delete the "alternateLocation" after everything is done, but it deletes the target directory instead -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.directory}/alternateLocation</directory>
</fileset>
</filesets>
<excludeDefaultDirectories>${project.build.directory}</excludeDefaultDirectories>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The clean plugin is basically deleting the target directory by default.
So how can I delete the "alternateLocation" folder from the target directory at the end of the build. (I guess you can do it using the maven-antrun-plugin but i don't want to use this plugin.).
You can solved this by using the maven-assembly-plugin via the predefined descriptor jar-with-dependencies which can be done by the following:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</project>
Than you don't need supplemental configuration.

Multiple XSD schemas for castor with castor-maven-plugin

Is it possible to work with multiple xsd schemas with castor-maven-plugin simultaneously?
I use it in rotation (schema1 and schema2) in POM and it works:
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
with a little problem: mvn:install collects all classes to target except chema2.crd (or schema1 if I use schema2). I have to copy file manually.
Can I fix it? Are there any ways to configure castor-maven-plugin ?
Try using multiple executions like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>firstSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
</execution>
<execution>
<id>secondSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema2.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema2.beans</packaging>
</configuration>
</execution>
</executions>
</plugin>

How can I combine jars using Maven?

The following snippet creates 2 JARS:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-dependency</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dependency</classifier>
<classesDirectory>${project.build.directory}\dependency</classesDirectory>
<includes>
<include>${dependancyInclude}</include>
</includes>
</configuration>
</execution>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>module</classifier>
<classesDirectory>${project.build.directory}\classes</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
I would like to combine these two JARs into one using the assembly plugin, currently I have the following:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- Combine all the JARs in the /target folder into one JAR -->
<execution>
<id>make-assembly</id>
<phase>compile</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Currently only one of the two JARS in included in the final JAR that is created by the assembly plugin.
If I understand you correctly, you actually want to merge the jar files into one big jar file. This can be achieved using the maven-shade-plugin (instead of the maven-assembly-plugin).
For example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<!-- Put your configuration here, if you need any extra settings.
(You should be okay with the defaults). -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

unpack dependency and repack classes using maven?

I am trying to unpack a maven artifact A and repack it into a new jar file in the maven project B.
Unpacking class files from artifact A into:
<my.classes.folder>${project.build.directory}/staging</my.classes.folder>
works fine using this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.test</groupId>
<artifactId>mvn-sample</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${my.classes.folder}</outputDirectory>
<includes>**/*.class,**/*.xml</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
In the same pom I now want to generate an additional jar containing the classes just unpacked:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesdirectory>${my.classes.folder}</classesdirectory>
<classifier>sample</classifier>
</configuration>
</execution>
</executions>
</plugin>
A new jar is created but it does not contain the classes from the:
${my.classes.folder}
its simply a copy of the default project jar. Any ideas?
I have tried to follow this guide:
http://jkrishnaraotech.blogspot.dk/2011/06/unpack-remove-some-classes-and-repack.html
but its not working.
I would suggest you to use the maven-shade-plugin instead.
That will make the unpack-repack in the same invocation.
You could do something like this for example:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>com.test:mvn-sample:1.0.0-SNAPSHOT</artifact>
<includes>
<include>**/*.class</include>
<include>**/*.xml</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
In the sample you have <classesdirectory>, the docs have the element as <classesDirectory>. Case sensitivity matters, I think.

Resources