I was wondering if it is possible to embed an OSGi container like Karaf inside a Tomcat instance. According to this SO question and a few others, it seems like its possible, but I can't seem to find any solid details on how to do this or what pitfalls/caveats to watch out for.
So:
Is it possible to embed an OSGi container inside Tomcat, so that I can hot-deploy OSGi bundles at any point to this container without having to restart Tomcat?
If the answer to #1 above is "yes", then what system services/ports does embedding OSGi inside Tomcat expose? I ask because I would like to deploy OSGi in a Tomcat server hosted on a Java PaaS where I don't have admin rights. And I'm wondering if - when I try to deploy the embedded OSGi container to Tomcat, that it will try to start listening on ports, or perhaps start doing something to the local file system. If this is the case I will likely receive security/permission errors.
Thanks in advance!
Is it possible to embed an OSGi container inside Tomcat?
Yes. In fact if you download Karaf and look in <KARAF_HOME>/demos/web you'll find a demo project that does exactly that.
what system services/ports does embedding OSGi inside Tomcat expose?
That would depend on what you install in it and how you configure it. Here is somewhat old (but IMHO stil relevant) discussion about default ports and how to configure them.
We deploy our application in the same fashion. We have deployed karaf in tomcat & on weblogic using a servelt bridge. The reason for using the container was to get past environment constraints where some customers are a "oracle" or an "ibm" shop and want all deployments done on these servers.
Since you will be using a servlet bridge it does not need to open a new port to list to http traffic. You may have issues with the karaf console if that port is blocked. Also I recall having issues with running cxf due to an embedded jetty instance it starts on another port.
Other than the ports you will need a karaf home directory with write access.
Related
At first i want to say that i'm a beginner in java servers and never deploy an java .war app on server other than localhost in my intellij.
I have a simple only REST app Which work fine in localhost, i also created war file and deploy it by command "asadmin deploy --port 4849 war_name", but when i go into url http://stachurskipiotr4.usermd.net/cookbook-1.0-SNAPSHOT there is an server error.
I completely don't know what it is, i will be grateful for any help.
Access the domain port for that case. Default is 8080 if you haven't configured.
http://stachurskipiotr4.usermd.net:8080/cookbook-1.0-SNAPSHOT
Also, please use or log in your admin console to see the apps if it's deployed. You can also access it directly from there.
Glassfish already provides the Jackson libraries and the version conflicts with the one Spring depends on. Glassfish is an enterprise container, is there a specific need for the enterprise container? Try a regular servlet container like Tomcat instead. If you do want enterprise, maybe you shouldn't need using Spring
EDIT:
Removing jackson jars from your project won't help you; Spring code wants the version it wants. You can try to find out which version Glassfish provides and then see which version of Spring depends on that and use that version of Spring. This is a wrong thing to try as this will be just the tip of the iceberg. Do not try to deploy Spring code in an enterprise container, these are competing specs.
Your options are
1) figure out why is Tomcat not working. Tomcat is a battle-tested servlet container with thousands of production deployments.
2) Try a different servlet container such as Jetty.
3) Rewrite your code to the JEE specification and deploy to an enterprise container such as Glassfish or Wildfly (there are others).
4) Use Spring Boot to embed the container and package your app as an executable jar.
EDIT2:
If you chose Spring Boot, your artifact will be an executable jar, you do not deploy it into a container since the container is embedded. You start the jar via a java command. You remove the container from your deployment entirely. I don't know your deployment environment, but you do not use Glassfish at all at this point, you have to run the java command to start the server.
If Glassfish is a requirement, you have to rewrite your code
So I am new to JBoss and this might seem a little too trivial, but here goes. I have a downloaded version of JBoss on my remote and I basically want to start a cluster of HA-JNDI using the all/deploy/cluster directory. But what confuses me is what tells JBoss to run only the HA-JNDI cluster when I start JBoss? I have the hajndi-jboss-beans.xml to configure the HA-JNDI, but what if I do not want to start similar JBoss services. What do I have to do to achieve that? Please let me know if you need any other information. Thanks!
Use the {JBoss}/server/all server as a template for creating JBoss instances, since it is set up for clustering.
Copy the /all server as a new server (i.e: {JBoss}/server/ha).
Make configuration changes, such as removing unneeded JBoss services
(see JBoss Application Framework Trimming guide).
I am trying to deploy a JSP/servlet onto a server. Not tomcat but on a real web domain. This is my first time doing so and so far I exported it into a war file and placed the file onto the server. Nothing happened which is why I am here. All the google searches seem to concentrate on Tomcat which I have already ran the project on. Advice?
Ok, let's get really basic. You want to see the compiled JSP in a browser, through some public URL, right?
First, find a place to host your application. You can try Digital Ocean (starts at $5/mo), EATJ (free version available), Amazon AWS (free trial available), OpenShift (free gears available), your own computer with dynamic DNS, or many other options available through Google.
Next, you packed your compiled code to a war file. That war file needs to be unpacked (deployed) using some software.
There are numerous ways to handle this (Tomcat, Jetty, Glassfish, etc.). They all have their pros and cons. Pick one and learn the very basics. Tomcat doesn't require a separate web server but you can set one up with it if you like. At this stage, I would keep it simple and not do that yet.
Lastly, set up GoDaddy (or whomever you used to get your URL) to point to the IP address of that server. If your server is running and enough time has passed for the changes to propagate, you should see your page.
There are plenty other J2EE server for example, JBoss and Glassfish. Each one has it's own way to deploy your war files. For example, Glassfish is throught a web administration console (https://docs.oracle.com/cd/E19798-01/821-1757/6nmni99aj/index.html) and in JBoss you need to deploy the war file in a specific directory (http://docs.jboss.org/jbossweb/3.0.x/deployer-howto.html).
It depends on which J2EE server you are using.
Now if you want to get your own server and configure it:
Get the server or VPS
Install JAVA
Install Apache
Install a J2EE server (I prefer glassfish)
Configure glassfish with apache (http://www.codefactorycr.com/glassfish-behind-apache.html) to use apache in front of glassfish
You may want to block the ports 4848 and 8080 used by glassfish
Deploy your webapp
Have fun!!!
PS: I'm assuming you have root access to the server
Easy Apache Tomcat 7 install after,
Run Code via SSH:
/usr/local/cpanel/scripts/addservlets2 --domain=domain.com
For Linux.
I have a standalone java application which uses java based TCP NIO to collect some information from various clients (not on web/HTTP but through some indigenously developed middleware). Now I have to develop a front-end for the users to perform a lot of querying through HTTP. So is there a way to put this application inside tomcat, so that servlets can invoke required functions on this application ???
The thing is it has to listen on that middleware outside tomcat too and at the same time service servlets inside tomcat. How to do this ??
Putting this application outside tomcat and using RMI is an option but I don’t want to do that.
Can embedding tomcat inside my application is an option ???
The brand-new Tomcat 7 has Embedded version for download.
Tomcat is big. You should try to embed Jetty, which is meant in order to make it possible.
http://jetty.codehaus.org/jetty/
I don't know about embedding Tomcat, but you can embed a servlet container inside your application using embedded Jetty. If what you want is to add an HTTP interface to an existing server, I think that's the way to go.
It also should be perfectly workable to launch your server's TCP listening components from a standard servlet in Tomcat. Then the servlet can call methods in your existing application directly, while it continues to listen to its usual TCP ports.
A third option is to write a servlet that just talks to your existing server in the same way other clients do.
The way you want to go, is to have an embedded web server to your existing application since you just need a little bit of web functionality.
Going the other way is possible. You can use servlet listeners to get started and stopped, and you need to take great care of any thread you start since Tomcat have no idea they exist.
As Traroth said, embedding Jetty is a much better option than doing the same with Tomcat. You have an example and a small tutorial in the Jetty website:
http://docs.codehaus.org/display/JETTY/Embedding+Jetty
You can always open the ports and listen manually if the requests aren't complicated.
Have you considered going the other way? That is embedding your application inside a web application?
Using spring you can instantiate your web application and then inject in into the appropriate web classes (e.g. struts2 actions).
This way you can deploy your web application into any web server that is preconfigured separate from your application.
If you do have to use Tomcat, you're best just making your application as a .war file which when Tomcat is ran will deploy your code. This can then talk to any RMI/middleware you like.
I'm not sure I understand your comment regarding memory spaces.
At a very basic level you have two choices:
Run your appication and the web
application in the same virtual
machine.
Run your application and
the web application in a different
virtual machine
If you take approach 1, you will be able to get instances of your applications classes from the servlets and call methods on them.
Embed tomcat / jetty inside your application. You will start your application normally through its main method. After starting your app you will need to create instances of the tomcat / jetty classes which will start up their own threads.
Embed your application inside a war file to be deployed on tomcat / jetty. Similar to the previous option instead you will need to start your application from a context listener.
If you prefer approach 2; start tomcat / jetty and deploy your web app and separately deploy your application. You'll now have two jvms running. To communicate between these two processes you'll have to use some form of socket communication: OutputStream/InputStream over sockets; RMI; JMX; JMS etc.
I am searching any way for embedding Weblogic server in Java , I know its possible because we have maven plugins for Weblogic which embeds Weblogic in maven, But googling for it did'nt gave me useful output, Does anybody know how can we embed wemlogic in java program ?
WebLogic doesn't provide an embedded API so, even if it's a pure Java Server and if you can thus call weblogic.Server from Java code, you will have to handle everything yourself (starting the container, waiting until it's started, deploying things, waiting until they are deployed, etc). In other words, this will require some work.
Maybe have a look at the sources of Cargo, although Cargo isn't really starting an embedded Weblogic (i.e. running weblogic.Server in the same JVM). This will give you an idea of what has to be done. Or, depending on your needs, use Cargo Java API.
But if you need a full Java EE server and if this is an option, I would use GlassFish v3 in embedded mode instead of WebLogic, it will be much simpler. Check the following links and see yourself:
Embedding Glassfish V3 in Unit Test - Two Jars, Three Lines Of Code And Five Seconds Start With Deployment
Embedding EJB 3.1 Container Into Your Unit Tests - Boot Time: 5 Seconds
Using the EJBContainer API with or without Maven (but with GlassFish v3)
TOTD #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3
Do you need WLS specifically, of any servlet container would do? If the latter is OK, then use Jetty.
WLS is not designed to be embeddable. But you can do it. After all, WLS is just a class named weblogic.Server. Setup classpath correctly, setup PATH and other environment variables (see setDomainEnv.sh and startWeblogic.sh), start that class from Java, and you have an "embedded" WLS.
There is probably a way, but I don't know it. My experience from writing maven plugins tells me that the most likely way that the plugin works is that it starts up a new command line process just like you would normally start up the server. So in a sense, not really embedded it.
The best way to see is to track down the source of the plugin and see how they did it.
WebLogic doesn't support embedded mode like Glassfish but you can have control over your Weblogic using "WebLogic Maven Plugin", this provide several maven goals for managing and working with Weblogic instance.
See this link for further information.