how to deploy Maven dependencies automatically into JBoss as OSGI bundles? - maven

I have a project that deploys an standalone OSGí Apache ServiceMix application. It has tons of dependencies and it is built with Maven. Now I want to deploy this application into a JBoss AS. I found an interesting Maven plugin called jboss-as-maven-plugin (org.jboss.as.plugins) to deploy anything. I use maven-bundle-plugin (org.apache.felix) to construct my bundles and it works fine, but when I deploy the project bundles, the deployment fails because dependencies are not satisfied.
How can I automatically bundle and deploy all the dependency tree with a Maven goal? Is it possible? My project has dozens of dependencies declared on the pom.xml and some of them are other projects in my workspace.

Currently the only solution to this I know are the Karaf features. You can create a feature file out of your pom dependencies.
I found that jboss seems to support subsystems. That may help to specify the bundles required to run your application. It does not seem to be the OSGi subsystem spec but for jboss this may already help. For OSGi spec 5 there is the standardized subsystem spec which may provide a standard way to do this across containers.
If jboss supports OBR (OSGi bundle repository) then you can limit the number of dependencies you have to specify.

If your application do not use OSGi per see, you may consider packing your application as a WAR which is deployable in JBoss.
Then you would need to use web.xml to bootstrap your application, such as using a Spring XML file.
There is a Camel example as a WAR here: http://camel.apache.org/servlet-tomcat-example.html

You can autoinstall your bundles with org.apache.sling plugin
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<executions>
<execution>
<id>install-bundle</id>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
<configuration>
<slingUrl>http://localhost:8181/system/console/install</slingUrl>
<user>karaf</user>
<password>karaf</password>
</configuration>
</plugin>
you can find detailed pom.xml from Adobe website :https://docs.adobe.com/docs/en/cq/5-6-1/developing/developmenttools/how-to-build-aem-projects-using-apache-maven.html
or http://www.cqblueprints.com/tipsandtricks/build-and-deploy-osgi/build-deploy-osgi-1.html

Related

liferay-maven-plugin + direct-deploy configuration for DXP

I'm currently on Liferay 6.2 (with Tomcat), and I can configure the liferay-maven-plugin in my Liferay hook project's maven pom.xml as below, in order to pre-process my hook WAR for hot deployment (using the direct-deploy goal of the plugin).
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>6.2.1</version>
<executions>
<execution>
<id>pre-process-war</id>
<phase>package</phase>
<goals>
<goal>direct-deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<appServerDeployDir>${project.basedir}/target/liferay-pre-process</appServerDeployDir>
<liferayVersion>6.2.1</liferayVersion>
<pluginType>hook</pluginType>
<unpackWar>false</unpackWar>
</configuration>
</plugin>
I'm now trying to migrate this hook to Liferay 7.2.1 CE. There is no plan to redesign this as an OSGI module at the moment i.e. it would continue to be packaged as a WAR. So how would my new direct-deploy configuration look like, with Liferay 7.2.1? Specifically:
a) Can I continue using the same Maven plugin? I see from this doc that the liferay-maven-plugin has been "removed", yet my understanding from other help pages is that this plugin should not be used only with the newer, OSGI-module style plugins (the latter makes more sense to me).
b) If I can continue using the same Maven plugin, which version of the plugin works with 7.2.1? Also, which liferayVersion value should I use here? I tried a bunch of combinations and none of them worked.
For instance, I first tried liferayVersion 7.2.1 but the build failed while running the direct-deploy goal, since Maven didn't find a com.liferay.portal:portal-web artifact with that version. So I tried the latest version of that artifact from Maven Central, which is 7.0.2, as my liferayVersion. But the build failed again, this time because it couldn't locate the corresponding version of com.liferay.portal:portal-service. There's no 7.x version of portal-service though, which makes sense because it's been replaced with the portal-kernel artifact. Not specifying liferayVersion doesn't work either.
I received a response in a Liferay forum which suggests that the liferay-maven-plugin has indeed been removed in Liferay 7.x, and so the only option left is to copy the WAR to Liferay's deploy folder and let it do the pre-processing at deploy time (as opposed to doing this at build time, with the Maven plugin). Given the lack of alternatives at this point, that seems to be the only way forward (and it works).

Gradle not recognizing Cumulocity Microservice SDK package

I managed to deploy a standalone microservice instance into Cumulocity platform according to documentation.
After deploying microservice to the platform, I am able to subscribe and make REST calls to the service, so everything works as expected.
Cumulocity Microservice SDK is based on Maven, therefore I have correct pom.xml specified.
The problem that I encounter is that I also have Gradle enabled in the project and CI setup based on Gradle in Gitlab and although everything works as should in Maven, the Microservice SDK package is not recognized by Gradle and I can't find a way to make it work. For example specific Microservice annotations that come up with the SDK are not recognized:
error: cannot find symbol #MicroserviceApplication
My current Maven specification includes:
<plugin>
<groupId>com.nsn.cumulocity.clients-java</groupId>
<artifactId>microservice-package-maven-plugin</artifactId>
<version>${c8y.version}</version>
<configuration>
...
</configuration>
<executions>
<execution>
...
</execution>
</executions>
</plugin>
My current Gradle specification includes:
dependencies {
compile 'com.nsn.cumulocity.clients-java:java-client:8.13.0'
}
I could rewrite CI specification to use only Maven but I was wondering, is there any way to make Gradle recognize Cumulocity Microservice SDK plugin from Maven?
java-clients is not what you need. Try 'com.nsn.cumulocity.clients-java:microservice-autoconfigure:8.13.0'. That's where the #MicroserviceApplication annotation should be.

TypeNotPresentExceptionProxy error at integration-test with maven-failsafe-plugin spring-boot 1.4

I'm getting ArrayStoreException: TypeNotPresentExceptionProxy when running integration-test with maven-failsafe-plugin and spring-boot 1.4.
You can see this error if you run joinfaces-example with
mvn -Pattach-integration-test clean install
I realized that the error does not occur if I change spring-boot-maven-plugin to run at pre-integration-test phase instead of package one.
More, this error started when I upgraded spring boot to 1.4. No error occurs if I change jsf-spring-boot-parent version to 2.0.0 which uses spring boot 1.3 version.
I actually found the answer in Spring Boot 1.4 release notes, short answer is that maven-failsafe-plugin is not compatible with Spring Boot 1.4's new executable layout. Full explanation below :
As of Failsafe 2.19, target/classes is no longer on the classpath and
the project’s built jar is used instead. The plugin won’t be able to
find your classes due to the change in the executable jar layout.
There are two ways to work around this issue:
Downgrade to 2.18.1 so that you use target/classes instead
Configure the spring-boot-maven-plugin to use a classifier for the
repackage goal. That way, the original jar will be available and used
by the plugin. For example :
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
An alternative is documented here: https://github.com/spring-projects/spring-boot/issues/6254
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!--
Make failsafe and spring-boot repackage play nice together,
see https://github.com/spring-projects/spring-boot/issues/6254
-->
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
</configuration>
</plugin>
This worked better for me, because when I used the "exec" solution, Spring failed to find my configuration files when starting the container. Which could probably be fixed by adding some further configuration parameters, I suppose, but this solution works "out of the box" for me.

Sling deploy content and bundle with maven

Iam searching for a maven based solution to deploy apache sling bundle and content (including jsp/html, etc files) on my sling standalone server.
I stated this private project to learn about sightly and sling models without using AEM. It is my first only sling project.
Ive created a sling bundle and a sling content project from the specific archetypes. Ive stated working with the Eclipse Sling IDE tools, but iam used to IntelliJ and there is no plugin to deploy the contetent the same way. I think its possible to build and deploy a package with both (bundle and content) by using maven.
Hopefully someone of you have some instructions or ideas to solve this problem and make it more comfortable developing web projects with apache sling.
Cheers ;)
The maven-sling-plugin can install bundles in a Sling instance, and bundles can include initial content which is installed when they become active.
The slingbucks sample demonstrates this, if you build it as shown below it will be installed in the Sling instance running on port 8080 and its initial content (defined under src/main/resources/SLING-CONTENT as specified in that module's pom.xml) will be installed:
mvn clean install org.apache.sling:maven-sling-plugin:install -Dsling.url=http://localhost:8080/system/console
If you use the Sling parent pom you can also use the autoInstallBundle profile to do the same thing using the default URL that that pom defines:
mvn clean install -P autoInstallBundle
This project may help you https://github.com/auniverseaway/slick, see the pom.xml file there
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Sling-Initial-Content>
jcr_root/content;
overwriteProperties:=false;
overwrite:=false;
uninstall:=false;
path:=/content;
maven:mount:=false,
jcr_root/apps/slick;
overwrite:=true;
path:=/apps/slick;
maven:mount:=false,
jcr_root/apps/sling;
overwrite:=true;
path:=/apps/sling;
maven:mount:=false,
jcr_root/etc;
path:=/etc;
overwriteProperties:=false;
uninstall:=false,
jcr_root/i18n;
path:=/etc/i18n/net.zum.slick;
overwrite:=true;uninstall:=true
</Sling-Initial-Content>
<Bundle-Activator>net.zum.slick.internal.Activator</Bundle-Activator>
<Sling-Model-Packages>
net.zum.slick
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
All in all the files inside the directories defined in <Sling-Initial-Content> space of the maven-bundle-plugin will be deployed with the bundle, correct?

How to auto-deploy EJB jar with TomEE maven plugin

I have a stateless EJB SOAP Web Service that is packaged in jar file.
Is it possible to setup auto-deploy with Tomee maven plugin when the app consists of only one EJB jar file?
For example, this site indicates that a web context defined in server.xml is required. My synch setup is same as the site suggests.
mvn compile
command does nothing but compile the sources as it normally does.
Is there a possibility to setup something like this with EJB jar or is a WAR package needed in any case?
Thanks.
UPDATE
In order to get the TomEE Maven plugin to work at all with jar files, I added the following in pom.xml configuration section
<apps>
<app>my.group:my-ejb-app:1.0:jar</app>
</apps>
We use the maven tomcat7 plugin to do exactly this. Here's the trick, because Apache TomEE is JEE6, you can deploy EJBs in wars.
So there are two ways to do what you want... One, skip the Jar packaging for your application and make your EJBs be WARs. If this doesn't sound appealing, the other way is to create a separate project that's a WAR, but pulls in your EJB jar as a dependency.
In either case, then you can then use the tomcat7 plugin to deploy your projects easily to Apache TomEE like this mvn tomcat7:deploy provided you fill out the server section of your pom correctly. Example:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<server>crabs</server>
<url>http://crabs/manager/text</url>
<path>/${project.artifactId}</path>
<update>true</update>
</configuration>
</plugin>
</plugins>
</build>
Make sure you have a user in tomcat-users.xml on the server that has the proper deployment permissions to manager-text. Also, put the server configuration into your ~/.m2/settings.xml:
...
<servers>
<server>
<id>crabs</id>
<username>deploy</username>
<password>your password</password>
</server>
...

Resources