How to deploy a karaf feature from a local maven repository? - maven

I've created by first project for karaf (4.0.1). So far I've got the following:
an application bundle built with the maven-bundle-plugin. There are going to be more...
a karaf feature created with the karaf-maven-plugin.
a karaf-assembly created with the same plugin
So I'm ready to deliver to the customer - but I'm stuck over the development process. This question answered almost all my remaining questions save one:
After having built my project by running maven install I think I should be able to to get my feature running on a local karaf instance using something like the command feature:install.
I can install my application bundle from local maven by using bundle:install but then I'm down to managing dependencies myself.
Really can't figure out while bundle:install works against my local maven repository and feature:install doesn't.

Found the soloution here. I knew I'd need feature:repo-add - but the name of this command and the official documentation sent me thinking in entirely the wrong direction.
This command does not add a (maven) repository, but adds the location of a feature in the maven repository chain (so I'm thinking the old name addUrl was probably easier to understand).
Anyway - using feature:repo-add mvn:<groupId>/<artifactId>/<version>/xml/features works.

I've just had the similar issue and I've found solution here: http://karaf.922171.n3.nabble.com/Add-additional-local-maven-repository-how-td4028299.html
I've edited the etc/org.ops4j.pax.url.mvn.cfg and uncommented the option org.ops4j.pax.url.mvn.localRepository, setting it to my local repository location:
org.ops4j.pax.url.mvn.localRepository=C:/data/maven-repo

Before installing a feature, you have to register the features repository that provides the feature using feature:repo-add
using feature:repo-add mvn:<groupId>/<artifactId>/<version>/xml

Related

Use Maven to start programs

I apologize if this sounds to simple (or the fact that there are other links that define this problem) - but I'm a complete beginner to Maven and even Java.
All that I'm trying to do is to run this code to see what it does:
https://github.com/semanticvectors/semanticvectors/wiki/GettingStarted
The Wiki says that uses can either download the .jar file or use the maven repo. I downloaded their .jar file and tried to run it but failed. I use this code:
java -jar /home/user/semanticvectors-5.6.jar
That .jar file didn't work for me and from other stackoverflow links, it seems that either the .jar file is not setup properly or I have a non-compatitble java version.
In any case, I've decided to try using Maven to get this running. I've installed Maven using:
sudo apt-get install maven
It seems to be working as everything was successful in setup. But now I'm not too sure what to do after. This Wiki (linked above) as go to this Maven repo site (https://oss.sonatype.org/#nexus-search;quick%7Esemanticvectors). To my understanding (and correct me if I'm wrong) I thought Maven is a super repository for developers and testers to work from the same code, so I thought I could use Maven as an alternative to running to program. Anyways, I'm open to any suggestions to get the program running to see what it does, thanks.
If you're interested in knowing more about me: I'm running a 16.04 Ubuntu system with Java 8.
The idea is that you can either build the JAR yourself - get the source from SVN and build it (using maven commands, as maven is a build tool), or you can use the existing JAR that is already "prepared" and ready for use in the maven-repository (nexus, in this case).
The result should be the same - if you use the JAR as a dependency in your code (add it to your pom.xml) or if you build it yourself.
You can learn more about Maven and things will be much clearer...

Gradle, OSGi and OBR (or other repository?)

previously I've been using Maven and the maven-bundle-plugin to archive the following:
When doing mvn install, local maven repo contains my bundle + all my bundle's deps automatically
Local repo becomes OBR repository by mvn bundle:index, also repository.xml is automatically updated with every mvn install.
Local repo can now be used for Karaf bundle deployment
Now, I'm looking to migrate some projects to Gradle, which is very nice in many ways. I'm successfully creating bundles using the 'org.dm.bundle' plugin (basic 'osgi' plugin did not allow me to auto-create service components).
By using Gradle's maven plugin I can do gradle install to install my own bundle in local maven repo. I could then use bindex to manually (or through some gradle hacking) index the repo.
However, my dependencies are not put into the maven repo, they are only stored in the gradle cache dir. Thus, I can not use the OBR repo to deploy in Karaf yet.
I've been looking around a lot trying to find some good solution to this, but I have not found anything.
I've looked at Karaf feature files, which would allow me to specify mvn URLs directly instead of relying on OBR, but I'd like to avoid messing with feature files manually.
There are references to using Nexus, but only Nexus Pro supports OBR from what I can see?
I'm up for suggestions on alternative solutions as well; the main goal is that I shall be able to deploy my bundles + deps in Karaf. Maven does not have to be used at all really, although I need some way for different Gradle projects to find dependencies from some other projects (which are not part of the same multi-project).
Any ideas or discussions to put me on the right track is appreciated!
This may be a bit late, but I just stumbled over your question while looking for a way to fetch with gradle from an OBR repository.
As far as I understood you want to push (gradle deploy) to some Maven repository and use it as an OBR repository. This is possible with Eclipse Package Drone, eclipse/packagedrone. You can deploy using Maven/Gradle deploy and let it generate a P2, OBR and OSGi R5 index repository.

How do I set up Spring and Maven environment for working offline?

I need to set up Spring and Maven for working offline. I am working with Spring Tool Suite.What environment variables do I need to configure besides M2 env var? When I try to add dependencies in pom.xml, and type springframework, nothing comes up in the search bar. I get "Core exception Could not calculate build plan Plugin org.apache.maven.plugins:m. I understand STS uses web services to locate the jars, so how do I configure Spring and Maven to work offline? Thank you.
Maven uses central repositoty to update dependencies via internet if you want run it offline you need to configure you local repository.See Setting local Maven repository
This is something that you will find very difficult or near impossible unless you somehow get all the relevant jars from spring and place them in your .m2 repo directory.
Your question has been asked a number of times on here ...
Have a look through these 2 questions which I assume is exactly what you have encountered.
Question 1
Question 2
Also one last note ...
After you setup your variables did you restart your PC I know sometimes I forget to do this when updating environment variables.
Before you go offline run the following:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
Once you've run that you can now build your project offline using the '-o' flag:
mvn install -o
It's also possible to configure the offline mode globally by setting the offline property in the ~/.m2/settings.xml file:
true

How to work with frequent local snapshot bundle deployments on Karaf?

I decided to build an application on top of OSGI and Karaf - I really like this stuff. However, I'm struggling a bit with a daily deployment on my local, development machine. I mean.. I make a change and then I would like to test it on my local Karaf instance. And it can happen like couple times per hour.
The way I'm doing it now is a maven build that creates a JAR bundle and then it's copied into the Karaf's deploy directory. I think that it isn't elegant at all.
I was trying to find a way around (google). I read about Karaf's features but it seems that despite the fact that it is a nice mechanism for deploying whole app, it doesn't solve my problem. As I understand it right, it does not check whether new version of my SNAPSHOT jar appeared in my local maven repo, right?
The key to make the update mechanism of karaf work is to deploy from maven instead of using the deploy folder.
Install you bundle like this:
install -s mvn:groupid/artifactID/version
or
install -s mvn:groupid/artifactID/version/typeOfMavenArtifact
Second one is useful for installing for example war/wab artifacts. Full maven protocol specification can be found here.
Then Karaf knows where the bundle came from. You can also check this using la -u. This makes karaf show the update location which now should be a maven uri. You will not that all karaf bundles have an update location like this.
When you now create a new build of your project using maven it will end up in you local maven repository.
Then simply run
update <bundleid>
This makes karaf check the update location (in your case you local maven repo) and reload the bundle from there.
You can even further automate this by using
dev:watch
or for karaf 3+
bundle:watch
This will make karaf check you maven repo for changes in SNAPSHOT bundles it has deployed and automatically redeploy these.
This also works very well together with the remote debugging. Use
export KARAF_DEBUG=true
before starting karaf. It then will listen for a debugger on port 5005.
You can then start a remote debug eclipse session on the same port and nicely debug your application in karaf. This works very well even if you change your bundle using one of the approaches above. So you can debug, find your problem, change the code, build and continue debugging with the changed version.
I also use this frequently when I work at the karaf code base itself as this also works for most of karaf's own bundles.

Jenkins : how to check out artifact from Nexus and Deploy on Tomcat-

I am tying to set up a Jenkins Pipeline.
The first stage is done, the code compiles, is tested, inspected and deployed to Nexus.
I would like now to make a second stage on the pipeline where the war is checked out from Nexus and deployed on tomcat.
Actually I already integrated the maven-tomcat plugin to deploy on Tomcat.
My question is how can I check out the latest build of the war ?
Is there any maven or jenkins plugin for that ?
Many thanks,
Patrick
Your binary repository manager (Nexus) should ideally occupy the following position in you overall architecture:
You can use Jenkins as your provisioning tool, but ideally it should launch some sort of process which pulls the artifact to be deployed directly from Nexus (If nothing else it's more efficient).
This is a lot easier than it sounds. For example the Nexus REST API could be called from a shell script to download any desired revision of an artifact. For example:
$CATALINA_HOME/bin/shutdown.sh
curl -o $CATALINA_HOME/webapps/myfile.war http://myrepo.com/service/local/artifact/maven/redirect?r=releases&g=com.myorg&a=myfile&v=1.1.1&e=war
$CATALINA_HOME/bin/startup.sh
Finally, perhaps you might wish to consider a dedicated system for managing your deployments? An interesting solution I've been playing with is rundeck, which has a plugin for Jenkins. I really like rundeck, due to it's simplicity a trait it shares with Jenkins. There is also a plugin for Nexus that enables rundeck to provide a pull down list of artfacts eligible for deployment.
See download-artifact-from-nexus.sh script at https://github.com/cescoffier/puppet-nexus/tree/master/files
In my case, I modified it to use wget instead of curl. For some reason, curl wouldn't work for me.
I suggest you create a new pom for this. That way you are not bound to jenkins.
You need not explicitly checkout the artifact from nexus (note that this is called downloading from the repository in maven speech). You can specify a different war file location in the tomcat maven plugin. See the documentation. For downloading the latest version from the repository see the answers to this question.
i get the same problem with curl, i solved it buy adding the parameter -L, so that curl will follow the redirection to download the artifact, wget follows the redirection by default.
Below syntax has worked for me.
wget --user=admin --password=admin http://192.168.0.3:8081/repository/simpleapp-snapshot/in/javahome/simple-app/3.0.0-SNAPSHOT/simple-app-3.0.0-20210513.143540-1.war

Resources