can we access osgi bundle from non osgi component for example can we access osgi bundle from non osgi struts2 action. if yes then how
thanks in advance
How is everything deployed, and what do you mean by access?
A bundle is just a jar file, so it can be used in a web service like any other jar. It is only an OSGi bundle when it is deployed in an OSGi framework. If you want to use it as a library, then there are no problems, many jars already work this way. If you want to access OSGi services, that is a different matter.
We can access osgi bundles from another applications
If you have an application which uses an entity class like MyClass.java when you deploy this entity as a bundle on the Apache Karaf,Eqiunox .. etc. OSGI containers
Another applications which might use same entity bundle which is already installed before
when you copy first tags from which is needed to be used
then paste it as dependency under your new project pom.xml
doing this
<groupId>gobito.enterprise.solution</groupId>
<artifactId>myapp</artifactId>
<version>0.0.1</version>
paste it to another applications as dependency and you can use
MyClass.java after you import package "gobito.enterprise.solution"
<dependency>
<groupId>gobito.enterprise.solution</groupId>
<artifactId>anotherapp</artifactId>
<version>0.0.1</version>
</dependency>
Related
I have a Spring Boot 2.1 web application. It works great. I can package it as either a WAR or a JAR.
In my pom.xml file I use:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
This application has many entity classes and quite a few Spring Data repositories. Almost always we deploy it as a WAR file.
Here's the question: sometimes we need to do a command line or batch process on our database. For example, we might want to run a process to resize all the images which are stored in the database, and that should be run by an administrator from the command line.
It would be great if mvn install would install a JAR file in the local Maven repository and I could use that artifact in another project to access my entity and repository definitions. I've tried many things, but whenever I build my project as a JAR file, and I look at the JAR, all my classes are within BOOT-INF/classes, which doens't allow them to be referenced from another project.
I was able to fix that by using a repackage goal in the spring-boot-maven-plugin. However, when I did that, it did generate a jar file but my CLI application couldn't start correctly with the repository beans created.
I read in the Spring Boot documentation:
Like a war file, a Spring Boot application is not intended to be used
as a dependency. If your application contains classes that you want to
share with other projects, the recommended approach is to move that
code into a separate module. The separate module can then be depended
upon by your application and other projects.
Is there any simpler way to do this, such that I don't have to create yet another project and manage that? Or is it a good practice to have a separate project for entities and Spring Data repositories?
So, in short words you just want to have a library with your entity and repositories? Then it should be enough to configure a simple maven project, a standard one, not inheriting from Spring Boot.
As spring Boot uses Spring Data JPA under the covers, you just need Spring Data JPA declarations, so add the dependency marking it as provided.
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>Some reference version<version>
<scope>provided<scope>
</dependency>
<dependencies>
This allows not to make the project include the Spring Data JPA dependency itself, as it will be included by the end project, which uses Spring Boot. However, you'll need to declare a reference version to use, you could take the one your current Spring Boot project uses (you can have a look in the maven dependency tree).
https://spring.io/projects/spring-data-jpa
Difference between maven scope compile and provided for JAR packaging
I am working on integrating fabric8 for my application and need to add fabric8 kubernetes and openshift client as OSGI bundles. I can get them from following maven repositories as JAR archives.
https://mvnrepository.com/artifact/io.fabric8/openshift-client/2.5.7
https://mvnrepository.com/artifact/io.fabric8/kubernetes-client/2.5.7
And and have to convert them to OSGI bundles to add them to my application since my application is only supporting bundles.
Is there a way to directly get the OSGI bundles of the above jars from maven repository as dependencies without converting them and adding them to a central repository ?
There is no direct way to get OSGI bundles, we have to build it manually.
We can make it available but we have to prepare the bundle and there are plenty of tools available,
For reference:
http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html
http://wso2.com/library/tutorials/develop-osgi-bundles-using-maven-bundle-plugin/
The kubernetes-client ships bundles for all its artifacts. The bundles are available on maven central and you can use them just by using the bundle classifier.
For example:
http://repo1.maven.org/maven2/io/fabric8/kubernetes-client/2.6.2/kubernetes-client-2.6.2-bundle.jar
Hey I am writting a project which includes 2 other maven project:
JPA with EJB project (DAO layer) packaging .jar
Rest Services Project packaging .war
I found help with setting dependency with eclipse. In my war project I've added local project with DAOs. Compiling, building(mvn clean install on two pom.xml) went succesfull. But I can't deploy it on wildfly server. I get NoClassDef of class from my jar package.
On the other hand I saw a lot of projects with DAO packing in jar. But there are EJB3 annotations. Will they work with JEE Server in that configuration?(They don't need web.xml so maybe it is correct). Which scope i have to set of my dependent DAO project? If i have NoClassDef error it seems there is no compiled classes at runtime, or there is 2 or more definitions of classes from this package. I've tried few configurations, but I can't get solution.
Could someone write best practice to setting maven projects? For example
DAO layer type: jar
Rest Services layer type: war, dependence: DAO { scope: default, type:jar}
I think a good practice would be to define a project parent (Parent POM), which must define the module involved:
<modules>
<module>application-dao</module>
<module>application-rest</module>
</modules>
and define as a dependency, your application ".jar"
<dependency>
<groupId>com.test</groupId>
<artifactId>application-dao</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
A recommendation you could add an extra layer of management, then you would
application-dao
application-core
application-rest
I'm trying to do some "hello world" example with Apache Camel. Just a simple route, deployed as OSGi bundle to Apache Karaf. And it's crazy, too many things to learn at once, Camel itself, integration with spring, integration with OSGi and Karaf...ugh.
I'm trying to follow the idea from here: http://www.andrejkoelewijn.com/wp/2008/10/19/simple-camel-dsl-osgi-bundle-example/.
I've created the bundle, the package with FileRoute.java file, etc, but I can't produce valid manifest.mf file, it's generated by "bundle plugin for maven" - so the POM file is used to generate the manifest file.
What's the problem is this in the manifest file, line with import packages:
Import-Package: com.company.foo.bar.demo;version="0.1",org.apache.ca
mel.builder;version="2.10",org.apache.camel.model;version="2.10",org.
apache.commons.logging
With error: "No available bundle exports package 'org.apache.camel.builder'" (and .model package).
Well, I understand what is the problem, but…How to expose these packages for the bundle?
Next I have there another bundle with Apache Camel context, so I thought that good idea is to expose the packages from there, through "export package", but it doesn't work, the camel bundle can't be build then.
I'm quite lost :( I'd really appreciate help or hint.
Thanks!
If you use Apache Camel 2.10 or better then the Maven archetypes is a good place to start a new Camel project. We have archetypes that can create OSGi based project for either spring-dm or OSGi blueprint. You chose which one you want to use. The project is then ready for OSGi as it setup a maven plugin that generated the needed osgi stuff for you. Only in more advanced cases you would need to tweak this plugin.
See details at: http://camel.apache.org/camel-maven-archetypes.html
If you use Maven 3.0.x then its much easier as you can just type
mvn archetype:generate
Then it runs in interactive mode, then type camel to filter only camel archetypes.
And then select the number for the archetype. eg for example the spring-dm to use OSGi with Spring.
Is it possible to have standard war deployment, which can be deployed on tomcat and also can be build as OSGi bundle and deployed with other bundles in OSGi container tomcat(i think virgo)?
Yes, there's a good deal of interoperability between WARs and WABs. Apache Aries and WebSphere Application Server will convert WARs to WABs on deployment. This is a good way to get up and running, but it's a better practice to use proper WABs in which you build in the OSGi metadata yourself. The extra OSGi headers won't interfere with the deployment in a normal Tomcat container, so the WAB has the greatest flexibility.
For your build, you have a number of options. For example, the maven bundle plugin can be configured to build WABs, or you can use Eclipse PDE's tooling support for OSGi metadata.
Pax-Url-War provides this functionality to containers like Apache Karaf. In brief, this allows you to import an URL like war:file:///path/to/myapp.war and Pax will wrap it as an OSGi bundle, optionally changing the URL root and other parameters on the fly.