how to create osgi bundle from jar - osgi-bundle

I am using MultipartbodyBuilder to send file and metadata from a REST web service client. To use
In my pom file I have added
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.2</version>
</dependency>
and also
<Embed-Dependency>
http-mime
</Embed-Dependency>
I have not added any bundle related to mime to this feature in the applications feature.xml
When I try to install the feature on karaf I get the following error in log files and it goes in Waiting
->net.sf.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null
2016-08-03 20:10:22,456[SpringOsgiExtenderThread-58]|ERROR|org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean|175-org.apache.cxf.cxf-rt-frontend-jaxrs-2.7.3|net.sf.cglib.core.CodeGenerationException : java.lang.RuntimeException-->net.sf.cglib.core.CodeGenerationException: java.lang.StackOverflowError-->null
I am using karaf osgi so I figured that I need to have a osgi bundle mapped to features.xml http mime is a jar without any bundle. There is a httpclient osgi bundle but it has other dependencies and it breaks my other projects mapped in features xml.
I want to know how to create an osgi bundle using httpmime 4.3.2 jar file. I am new to this so if some guidance and reference will help.

There is a karaf feature called wrap. This allows you to use also non OSGI jar files. In your feature.xml you just need to add the following bundle to your feature.
<bundle>wrap:mvn:org.apache.httpcomponents/httpmime/4.3.2</bundle>

Related

How to add external jars in/with Maven WITHOUT installing locally

Currently the way I'm referencing my Jars through my Spring Boot application is by using Maven dependency manager with a system path.
<dependency>
<groupId>example1.1</groupId>
<artifactId>example1.1</artifactId>
<version>1.1</version>
<scope>system</scope>
<systemPath>${basedir}/libs/example1.1.jar</systemPath>
</dependency>
... etc (30 more jars)
How would one avoid this way of loading of jars since I'm moving over to to publishing it as a jar and getting a error of:
should not point at files within the project directory,
${basedir}/libs/example1.1.jar will be unresolvable by dependent
projects
Any easy way to load multiple jars without putting them on the local system?
Cheers

How to exclude a bundle from Karaf Feature programatically

In my project, there is Karaf feature XML file contains all OSGi bundles. Now, this is used as dependency in other maven project's pom.xml file.
<dependency>
<groupId>a.b.c</groupId>
<artifactId>dummyfeature</artifactId>
<type>xml</type>
<classifier>features</classifier>
<version>1.0.0</version>
</dependency>
Now, following code is being used to install above feature.
KarafDistributionOption.features(
maven()
.groupId("a.b.c")
.artifactId("dummyfeature")
.version("1.0.0")
.type("xml")
.classifier("features"), "dummyfeature")
Is there a way to exclude a particular OSGi bundle from above feature programtically?
https://issues.apache.org/jira/browse/KARAF-5376 provides a way to alter the features read from XML file. You can:
blacklist some bundles
blacklist some features
override some bundles (like changing version or even group/artifact IDs)
override entire features
See this comment for overview of the mechanism. There's no documentation fragment yet (I didn't have time to do it). But for your particular case, you should add etc/org.apache.karaf.features.xml file with this content:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Configuration generated by Karaf Assembly Builder
-->
<featuresProcessing xmlns="http://karaf.apache.org/xmlns/features-processing/v1.0.0">
<blacklistedBundles>
<!-- there are several patterns you can use here -->
<bundle>mvn:groupId/artifactId</bundle>
<bundle>mvn:groupId/artifactId/1.0</bundle>
<bundle>mvn:groupId/artifactId/[1,2)</bundle>
</blacklistedBundles>
</featuresProcessing>

Websphere Liberty Profile: [WARNING ] SRVE0190E: File not found in library that is contained in the EAR file

Currently I have a problem during migrating a Java Enterprise project form old WAS-8 to Liberty Profile 17. In my case the environment cannto find a bunch of css/js files in the richfaces jar. Loading a page in the browser, WLP17 writes warnings like this into the logfile:
[WARNING ] SRVE0190E: File not found: /org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.5.17.Final/PackedCompressed/org.richfaces/jquery.js
I build the project using maven and I defined the richfaces dependency in the parent pom like this:
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces</artifactId>
<version>4.5.17.Final</version>
</dependency>
Then, I have several EJB and WAR projects that are packed together into an EAR file. The WAR projects using richfaces contain a richfaces dependency with scope provided:
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces</artifactId>
<scope>provided</scope>
</dependency>
Finally, the EAR pom has the dependency on richfaces to ensure that the library is included in the EAR file. For any reason the liberty is not able to find resources located in the richfaces jar.
I inspected the created EAR file, it contains the richfaces libraries. Then, I inspected the richfaces libraries, the also contain the files that are not found.
Is there any more configuration I have to do?
Jar libraries which are expected to serve static files from META-INF/resources/ should be bundled in the web application WAR. Section 4.6 from the Servlet 3.0 spec is relevant:
The getResource and getResourceAsStream methods take a String with a
leading “/” as an argument that gives the path of the resource
relative to the root of the context or relative to the
META-INF/resources directory of a JAR file inside the web
application’s WEB-INF/lib directory...
#wtlucy's comment did solve my problem. Thank you.
I have put the richfaces libraries into the WAR files that need these libraries.

URI is not registered. jasypt in blueprint.xml

I used jasypt for encryption in blueprint.xml of my OSGI application which'll be deployed in Jboss fuse server,
xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0
I'm seeing an error message in the xml file that "URI is not registered". I'm using IntelliJ as my IDE.
Can someone help me to resolve this? Should I need add any jar? Or any xsi:schemaLocation?
This's resolved, after adding the below dependency on my pom.xml,
<dependency>
<groupId>org.apache.karaf.jaas</groupId>
<artifactId>org.apache.karaf.jaas.jasypt</artifactId>
<version>2.3.4</version>
</dependency>
This dependency jar has the xsd karat-jasypt-1.0.0.xsd in it.

java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet, tomcat doesn't see javaee-api-7.0-b83.jar

I am trying to run sample guessnumber-jsf from Java EE tutorial. It is here: https://svn.java.net/svn/javaeetutorial~svn
There is no dependencies in pom.xml. So output file has no .jar file. When I try to put javaee-api-7.0-b83.jar inside tomcat/lib or WEB-INF/lib/javaee-api-7.0-b83.jar, nothing changes.
When I try to open
localhost:8080/guessnumber-jsf/faces/greeting.xhtml
I get ClassNotFoundException. Where can I get list of jars that I need for faces tutorial? How can I connect them?
You can't put that Java EE jar in Tomcat and expect it to magically morph into a Java EE server.
That particular jar only contains the APIs to link against (eg "headers" in C/C++ terminology). It does not contain any implementation.
The easiest thing to do is to dish Tomcat and download TomEE instead. Optionally download GlassFish.
These will all already contain all the functionality you need and nothing will have to be put into WEB-INF/lib. (if using Maven put the Java EE 6 GAV as a dependency with scope provided in your pom).
If you are using a Maven project you can fix this error by adding the following dependency:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.7</version>
</dependency>
Adding to the answer of Mike Braun, the Java EE 6 GAV for the web profile is:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6</version>
<scope>provided</scope>
</dependency>
Specifically note the scope: "provided". This means your Maven project will link against this, but it expects your runtime to have the implementations. For TomEE, GlassFish, JBoss AS 7.x, etc this is indeed the case.
In your classpath (.classpath) make sure you have entry like
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>

Resources