How to Create Spring Boot Thin and Fat Jar in Same Spring Boot Maven Project - spring-boot

I am having a need to build my spring boot project as both fat and thin jar,
Expected output: one fat jar and one thin jar
Actual output: both are fat jars. I extracted and checked, it contains BOOT-INF/lib having jars
Following is my build plugin configuration
spring boot version 2.4.3
spring boot thin version 1.0.25.RELEASE
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>create-fat-jar</id>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
<configuration>
<mainClass>com.mycomp.ExampleApplication</mainClass>
<addResources>true</addResources>
<finalName>${project.artifactId}-fat-${project.version}</finalName>
</configuration>
</execution>
<execution>
<id>create-thin-jar</id>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
<configuration>
<executable>false</executable>
<addResources>true</addResources>
<finalName>${project.artifactId}-thin-${project.version}</finalName>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>${springboot.thin.version}</version>
</dependency>
</dependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Please help me to resolve this issue.

There is an experimental thin layout project from Spring, try to use the below and it will help you.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.28.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
https://github.com/spring-projects-experimental/spring-boot-thin-launcher

I think creating a Fat jar in spring boot is very easy. The part of creating a Thin jar requires special changes in pom.xml file. Let me describe both scenarios here:
In both cases, the top part will be same:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.package</groupId>
<artifactId>YourApplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>YourApplication</name>
<description>Your description</description>
<properties>
<java.version>1.8</java.version>
<mainClass>com.package.YourApplication.Main</mainClass>
</properties>
pom.xml for fat jar:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
...
your other dependencies as well...
</dependencies>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<executable>true</executable>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugins>
The plugins are important. Because they provide specific build commands to maven.
Now, for thin jar creation:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- <scope>provided</scope>-->
</dependency>
...
your other dependencies as well...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
Here, you can see that in dependencies, tomcat provided scope is removed. Also, the plugins have changed. Executing mvn package then mvn install will generate the thin jar and copy all the dependencies outside the jar file in lib/ folder.
I hope this helps you. :)

Related

Why do I get "Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver"?

I tried some of the advices given on other similar questions here, but failed to overcome the problem.
I am getting this error when trying to execute the jar by:
java -jar AutoHotRouter-1.0.jar
Given the following pom.xml, what am I missing here??
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ttt</groupId>
<artifactId>AutoHotRouter</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>AutoHotRouter</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.53.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
First I added:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>com.ttt.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
I built the jar using
mvn clean install
then on
java -jar AutoHotRouter.jar
I got:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/openqa/selenium/WebDriver
Then I removed the previous plugins and added firstly maven-assembly-plugin and because it didn't work for me, I replaced it with maven-shade-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.ttt.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer implementation=
"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.ttt.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
after
mvn clean install
and then
java -jar AutoHotRouter-1.0.jar
I get:
no main manifest attribute
I also tried
mvn clean compile assembly:single
with
maven-assembly-plugin.
Then I got:
Error reading assemblies: No assembly descriptors found.
Thanks!
This is just an assumption since the pom looks good so far. The part that's a bit suspicious is the jar plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
...
It looks like you later on try to execute the created jar file with java -jar? In that case all the dependencies you define in the pom will be missing. Either use the dependency-plugin to collect the dependency jar files and use the classpath option when running the jar or use the shade-plugin to create an uber-jar that will contain your classes as well as the dependencies.
Using your pom allowed me to start Chrome, so the dependencies look good. So I think the way you start it causes that exception.
Update: since you use this setup to automate chrome, the shade plugin seems the best way to go. I am able to start chrome with this pom and main class in src/main/java
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>HotRouter</artifactId>
<version>1.0-SNAPSHOT</version>
<name>HotRouter</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.StartMain</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Main-Class
package org.example;
import org.openqa.selenium.chrome.ChromeDriver;
public class StartMain {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:/Program Files/Google/Chrome/Application/chrome.exe");
ChromeDriver driver = new ChromeDriver();
}
}
Then mvn package and java -jar ./target/HotRouter-1.0-SNAPSHOT.jar opens chrome. Your config is almost the same (I think only the phase config for the shade plugin is missing)
Its important to have the shade plugin within the <plugins> section of the pom, as it is not part of the default jar life-cycle. The <pluginManagement> section is just there to configure defaults for versions and configuration. See pom reference. So additional plugins will not be automatically enabled if only in that section.

How to pack a JMeter test plan built from code into a jar using Maven?

I'm attempting to build a JMeter test plan in Java. I can't seem to find much documentation on this process, and the resources I can find all use Maven to build the jar. I have no prior experience with Maven and cannot get my pom configuration right.
Main points of confusion:
If my jar goes in jmeter_home/lib/ext, does that make dependencies like ApacheJMeter_core and ApacheJMeter_http a provided situation?
There seem to be multiple Maven plugins (maven-jar, maven-assembly) with a similar purpose? Is there one that best suits my needs?
If I want to reference a non java resource in a place outside of the jar (somewhere else in the JMeter directory), does that require special consideration when configuring your POM?
Am I supposed to configure the jar to be executable, or does JMeter provide like a script to work with lib/ext jars?
Any insight on any of these points would be greatly appreciated.
These resources have guided me along, but I've wasted hours trying to solve this seemingly menial piece of the process..
https://bitbucket.org/blazemeter/jmeter-from-code/
https://github.com/piotrbo/jmeterpoc
If anyone has more resources on building JMeter test plans in code, PLEASE feel free to share!
Here's my pom.xml, I understand that there's probably some redundancy in my use of plugins and such, but that happens when you've been attacking the same problem for hours with no progress :)
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sweber</groupId>
<artifactId>jmeter-plugin</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>jmeter-plugin</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>
com.sweber.Main
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.sweber.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_core</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_java</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_http</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-casutg</artifactId>
<version>2.7</version>
</dependency>
</dependencies>
</project>
You need to add com.lazerycode.jmeter in the POM.
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin
So you add this to your pom :
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.9.0</version>
<executions>
<!-- Run JMeter tests -->
<execution>
<id>jmeter-tests</id>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
<!-- Fail build on errors in test -->
<execution>
<id>jmeter-check-results</id>
<goals>
<goal>results</goal>
</goals>
</execution>
</executions>
Also, if you're going to do in IDE testing, not just mvn clean verify, you'll have to unpack Jmeter dependencies to the target dir.
Using this in the project root directory : mvn com.lazerycode.jmeter:jmeter-maven-plugin:2.9.0:jmeter
Equivalent statement for any other mvn plugin : mvn groupId:artifactId:version:goal (based on POM structure of plugin)

Spring Boot jar executable - How to generate files to different directory similar as maven-dependency-plugin does

As straich question, why spring-boot-maven-plugin works but maven-assembly-plugin not in the pom below?
I have googled few hours and I red somewhere that we don't need maven-assembly-plugin if we use spring-boot-maven-plugin. It doesn't answer my question since I want to have more control in which folder my files are genereated. Along that, if I "mvn clean compile package assembly:single" I get two executable jars, one outcome of spring-boot-maven-plugin and another outcome of maven-assembly-plugin in my project target folder. The one generated by spring-boot-maven-plugin runs as expected when I start via command line (java -jar aws.scheduller-1.jar. On the opposite, if I try java -jar aws.scheduller-1-jar-with-dependencies.jar I get a message complaining that it wasn't possible to load ...config.BootApp (I googled a bit and I guess it is something related to certain default profile in Spring Boot).
That said, how can I use maven to package Spring-boot dependency in different folder than default target directory?
Main Class
#SpringBootApplication
#EnableScheduling
#ComponentScan({ "br.com.mycompany.tasks","br.com.mycompany.utils" })
#PropertySource("file:C:/temp/application.properties")
//#PropertySource("file:/home/ec2-user/JOBs/application.properties")
public class BootApp {
public static void main(String[] args) {
SpringApplication.run(new Object[] { BootApp.class }, args);
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>grpAwsScheduller</groupId>
<artifactId>aws.scheduller</artifactId>
<version>1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceencoding>UTF-8</project.build.sourceencoding>
<logback.version>1.1.9</logback.version>
<logstash-logback-encode.version>4.8</logstash-logback-encode.version>
<spring-boot-starter.version>1.4.3.RELEASE</spring-boot-starter.version>
<aws-java-sdk.version>1.11.73</aws-java-sdk.version>
<jdk.version.version>1.7</jdk.version.version>
<project.build.directory>C:/temp</project.build.directory>
<!-- Maven versions -->
<!-- https://maven.apache.org/plugins/ -->
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
<maven-dependency-plugin.version>3.0.0</maven-dependency-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.73</version>
</dependency>
<!-- <dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-java-sdk-sqs</artifactId>
<version>${aws-java-sdk.version}</version> </dependency> <dependency> <groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId> <version>${aws-java-sdk.version}</version>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash-logback-encode.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>br.com.MyCompany.config.BootApp</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>br.com.MyCompany.config.BootApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- <excludes> <exclude>**/log4j.properties</exclude> </excludes> -->
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>br.com.MyCompany.config.BootApp</mainClass>
<classpathPrefix>dependency-jars/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Maven Web Project with Apache Felix Plugin

What's the best way to create a simple osgi (deploying into virgo server) project using maven, to create a war structure with pom.xml maven descriptor?
A Structure target is
*.jsp
*.html
META-INF
MANIFEST (OSGI-CONFIG)
WEB-INF
classes
lib
web.xml
Then when I create a project
This is my pom.xml
project properties
<groupId>com.aaaa</groupId>
<artifactId>first-maven-virgo-project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
Felix Plugin
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Export-Package>com.roshka.servlet</Export-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Dependency>*;scope=compile|runtime;</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Web-ContextPath>/hello</Web-ContextPath>
<Webapp-Context>hello</Webapp-Context>
</instructions>
</configuration>
</plugin>
But, when I execute mvn install the package does not create the MANIFEST file, to package into METAINF folder.
What's the wrong with my felix project? What's is the typical pom.xml template to create an OSGI BUNDLE , and WAR OSGI BUNDLE?
p.s. if I change WAR TO BUNDLE into Packaging Maven descriptor, the JAR generated works OK, with MANIFEST generated OK. But it is not WEB Structure.
My question has been resolve with the next pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aaaa</groupId>
<artifactId>first-maven-virgo-project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<description>http://localhost:8090/system/console/bundles</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestFile>./src/main/webapp/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<supportedProjectTypes>
<supportedProjectType>war</supportedProjectType>
</supportedProjectTypes>
<manifestLocation>./src/main/webapp/META-INF</manifestLocation>
<instructions>
<Export-Package>com.roshka.servlet</Export-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-ClassPath>.,WEB-INF/classes,{maven-dependencies}</Bundle-ClassPath>
<Embed-Directory>WEB-INF/lib</Embed-Directory>
<Embed-Dependency>*;scope=compile|runtime;</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Web-ContextPath>/hello</Web-ContextPath>
<Webapp-Context>hello</Webapp-Context>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<Import-Package>javax.servlet,javax.servlet.http,javax.servlet.*,javax.servlet.jsp.*,javax.servlet.jsp.jstl.*,*</Import-Package>
<outputDirectory>./src/main/resources/WEB-INF/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<actTransitively>true</actTransitively>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Enable this plugin for all modules -->
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
</plugins>
</build>
There is an answer from IBM to be found here which describes the process step by step. A script could be developed to create a bundle given a war, I have written one in java, invoked as a build step.
One crucial difference is that the IBM steps leave the finished product as a jar, whereas jrey leaves his as a war file. This is possibly because the IBM steps might lead to further CICS bundling, which requires jars as far as I am aware, at least when using the RAD environment.

Include OSGI-INF to jar package after Maven compilation

I'm creating OSGi package and I want the Apache Felix SCR maven plugin to automatically include generated OSGI-INF folder to .jar package. Now it just generates OSGI-INF to target/scr-plugin-generated. This is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>maven.test</groupId>
<artifactId>test-dfs</artifactId>
<version>0.0.4-SNAPSHOT</version>
<name>DFS test</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.9.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
...
</dependency>
<dependency>
<!-- scr annotations - for generating component descriptors only -->
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
<version>1.7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<depl.user>user</depl.user>
<depl.password>password</depl.password>
<depl.host>localhost</depl.host>
<depl.port>4502</depl.port>
</properties>
</project>
if you use:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
</plugin>
instead maven-jar-plugin + maven-bundle-plugin (with manifest goal), all files generated by maven-scr-plugin will be included into a built bundle implicitly.

Resources