Embedding Felix in Tomcat - apache-felix

I am a newbie to OSGi, started using felix. I am at present well versed with the concept of bundles, service etc. I have a requirement where I can embed Felix into Tomcat, I tried googling the same but was unable to find a relevant solution for my purpose.
What I exactly need is..
Till now I used to deploy my web app bundles into embedded http jetty service/PAX web.. installed inside Felix, but now I want to put Felix into Apache Tomcat/any other application server, so that whenever my tomcat starts up I need my felix instance up and running, and at the same time should be able to deploy/install/start my bundles through felix.
Any kind of help would be greatly appreciated.

You might want to consider the Apache Sling Launchpad subproject. This creates a WAR file which can be deployed into any servlet container and which launches the Apache Felix framework as the OSGi framework.
See also the Sling Launchpad and Embedding Sling for more information.

Related

WebLogic and OSGi

Is there a way to run an OSGi container in the Weblogic Application Server? I know that it works with JBoss, Glassfish and there are possibilities to add an Equinox servlet bridge to your OSGi project (implementation of the bridge is too old). But I want something similar to JBoss/Glassfish functionality where it is very easy to deploy your OSGi environment, because there are already OSGi implementations. Most of the articels I found were very old and there are no more recent ones. Can someone help with hints or better some links?
Maybe Bnd could create a .war file for me, but how can I achieve it. I read there is a possibility. Example would be great!
EDIT
Just for those who still look into that case. Since version 12.1.2 Weblogic supports OSGi out-of-the-box.
I'd consider the Apache Felix Http bridge. It worked a lot better for me than the ancient Equinox bridge (I messed around with it for a while, but never got it to work well), after I switched to Felix I got something working pretty quickly.
If I understand you correctly, you want to make a 'plain' war file, that can be deployed in any Java EE server. If that's the case, there is nothing OSGi about your war file, so I don't think Bnd will do anything for you.
WebLogic now supports OSGi in version 12.1.2 . See this

jBPM and JBoss web app

Ok I'm having quite some issues setting both jbpm and jboss working together...something as simple as running the jbpm process from a servlet is trunning to be a pain and all because jBoss can't find classes.
I made a Dynamic Web Project and didn't use Maven project so things are cleaner...and because it should work.
I just want to load a jbpmn2.0 from the repository in a servlet and run it using a WorkItemHanlder....but I get this:
java.lang.ClassNotFoundException: org.drools.runtime.process.WorkItemHandler
For some reason jBoss can't find a class from jBPM that should work on JBoss. What I did....and I think it's not the right solution...was add the knowledge-api.jar to the WEB-INF/lib. Although I can now deploy the app when I try to run it I get:
Error Unable to instantiate service for Class 'org.drools.builder.KnowledgeBuilderFactoryService'
I Honestly don't get why is it so hard to make a Jboss Web app using jBpm.
You need to make sure all dependencies are on your classpath, this is the same for all Java applications (not just jbpm) and application servers (not just JBossAS).
Which jars did you add? Depending on which features you are using, there could be quite a number of jars that you need to add. One option would for example would be to extract the jars in the jBPM runtime zip that is part of the jBPM downloads into your WEB-INF/lib.
If you use Maven, you would be able to automatically derive all required jars.
Kris

Eclipse doesn't import all Axis2 jars but project still runs on Tomcat?

When I develop an Axis2 web service on Eclipse, I noticed that Eclipse is automatically copying the classes from the lib folder of Axis2 to the lib folder of the new project. However, not all classes from the lib folder of Axis2 are being copied. Interestingly, the web service runs without any problem when deployed to Tomcat via Eclipse even if some the jars from Axis2 were not copied. Also, when I viewed the temp file of Tomcat, Tomcat seems to generate the jars for the listed modules on modules.list of the web service.
Can someone enlighten me regarding what is happening on this? Why Eclipse doesn't copy all the jars from Axis2? Why can the web service run on Tomcat even without the other jars from Axis2? What are those temp files for? When and why is it being generated?
I tried to run the same project on WebSphere and I am encountering a ClassDefNotFound exception because of the missing jars. My problem was solved when I copied all the Axis2 jars that was not copied by Eclipse to my project. But I'm not comfortable with my solution because Tomcat can run my project even without those jars. Is my solution really the right solution? Or am I missing a configuration setting?
This is just for clarification:
My web service is already running in Axis2. My class loading policy is set to PARENT_LAST. I know that since WebSphere has its own Axis2 configuration, the class loading policy must be set to PARENT_LAST so that WebSphere will use the Axis2 from the project itself. Aside from setting the class loading policy, I did something to make my web service run on WebSphere. I describe what I did above. My question is why such method must be taken?
WebSphere has it's own axis2 configuration as part of its Java EE server spec for JAX-WS. Change your class loading policy to PARENT_LAST and check if that solves your problem.
Edit:
As the original post already states: WebSphere is a Java EE server depending on version it supports its the standard Java JAX-WS web services. Actually web services became part of the standard jdk.
If you use JAX-WS like mentioned in Introduction to JAX-WS or building web services then you don't have to add any 3rd party library for getting your web services running. As soon as you use the non JDK implementation like axis2 you have to package it with your application.
IBM didn't just pack the axis2 into their WAS/JDK, they modified it. I'm not sure what Tomcat delivers, however as long as you use JAX-WS it shouldn't matter. With JAX-WS you don't have any direct import of the org.apache.axis packages. If you use these imports you have to supply the libraries and make sure that yours are loaded.

Jboss4 inside OSGI

Is it possible to run Jboss 4.2.3 as a bundle inside OSGI container? What would be the challenges associated with it?
For those who cares, I am looking at running dcm4chee inside OSGI.
While not impossible it would be incredibly hard, a simpler alternative would be to embed OSGi inside JBoss, see:
http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html
and
Programmatically Start OSGi (Equinox)?
and
http://njbartlett.name/2011/03/07/embedding-osgi.html
http://www.dcm4che.org/jira/browse/DCM-308 Looks like they're adding support to make the Jars valid bundles - couldn't you just work out the dependencies and deploy these to an OSGi framework? OSGi has support for JMX and JNDI.
Unless there are huge dependencies on JBoss' internals, I'd suggest the second option, but beware of Class.forName usage and other non-osgi-friendly code.
I logged the bug specifically for the dcm4che (note 1 e) toolkits, not the dcm4chee war. I would suggest logging a new issue for the dcm4chee assembly. However, making the dcm4che toolkit components osgi bundles would likely be a required step in the direction of getting dcm4chee to run in an osgi container.

how to run the servlet in eclipse?

I want to run a servlet in Eclipse. For this I have created a dynamic web project and I have deployed my servlet.java file under the WEB-INF folder. I have also added the servlet.jar file. How can I run the file as a java application?
Servlets run in a servletcontainer. Servlets are not "plain vanilla" java applications. See, they do not have a main() method! Servlets listens on HTTP requests and returns HTTP responses through the network. Running the sole servlet class as a plain vanilla Java application doesn't automagically make them to listen and react on HTTP requests.
Apache Tomcat is a popular servletcontainer. Just download and unzip it. Then in Eclipse (I assume that you already have downloaded the Eclipse Java EE version, else drop it all together and redownload the right version), go to Servers view and add the newly installed Tomcat instance. Then create a Dynamic Web Project wherein you pick the newly integrated server instance from the list. Eclipse will then automatically take the Servlet API libraries in the classpath/buildpath (thus, you do NOT need to download a random "servlet.jar file" separately yourself! this is only receipt for major trouble). Then create a Servlet class and register it in web.xml. Then deploy the project to the newly integrated server and start it. Then in your favourite webbrowser go to http://hostname:port/contextname which is usually http://localhost:8080/webprojectname.
To learn more about servlets (and Eclipse and Tomcat) I strongly recommend you to go through those tutorials. You can also search on youtube for video tutorials using the obvious keywords.
Servlets run in servlet/JSP engines, like Tomcat or Resin or Jetty. You normally don't run them outside a container.
You can certainly deploy your app to a servlet/JSP engine and start in from Eclipse. But it's the app server that you run, which then acts as the home for your servlet.
Servlets cannot be run directly as an Java app.
I recommend two approaches:
Refactor your servlet and put your "java" code (what ever generic code you want to call) in another jar that you call from both the servlet and the Java application.
Run the servlet in a container in Eclipse. See http://www.eclipse.org/jetty/
Communicate with the servlet through HttpRequest's and HttpResponse's