I may be barking up the wrong tree here -- it's relatively easy to wrap a vanilla Java app in a daemon/service -- but it'd be really helpful for deployment if we could push pure Java apps onto a Glassfish server and have them start up automatically.
We use JMS to connect this app to several other beans living on the Glassfish server. We are actually using glassfish to "deploy" it to the production machine, but it doesn't start automatically. Have been looking into JCA, but it doesn't seem like quite what I'm looking for.
Thanks!
If your 'pure Java app' is packaged as .war you could add a ServletContextListner to your app that gets called when the application is loaded and that performs the starup of the application...
Related
I'm trying to build my own site where initially I will only host my profile and resume but will also build and publish some simple web applications that I can use as coding samples for jobs. The idea is people can see a demo of the apps and then see the code on github.
Can I do all this using only tomcat or should I use another server for this purpose?
I have heard that tomcat should only be used for java web applications but I've tried it locally and it seems to work...
You can totally do it all with tomcat.
Arguably, tomcat is not as efficient as apache or ngnix for serving static assets, 10% less so, and does not scale as well. There's a good article on the subject here:
http://tomcat.apache.org/tomcat-3.2-doc/tomcat-apache-howto.html
This is not not going to be an issue for you with a small site. Go with what gets you up and running the fastest.
If you want, later you can show off your technical prowess by running tomcat behind a web server. You can tell folks at interviews the story.
We building a Netty/NIO based service, and I'm considering the deployment of this service to our production environment. Our standard way of deploying services is as WARs, to be deployed inside Tomcats.
When I suggested the same approach here, I got shouts and complaints that "it shouldn't be done", because both Netty and Tomcat are servers, and "it doesn't make sense to host one server in another".
To me it makes perfect sense because it completely solves my deployment issue, as well as saves me from writing some other code. Why is it such a big "no no" ?
The dynamic WAR deploying and undeploying that Tomcat provides are designed for web applications. The Netty application you are trying to deploy into Tomcat is not a web application but just a separate server that only shares the VM memory. It means Tomcat has been repurposed into a generic microkernel such as OSGi.
However, I don't think it's a big problem. Since your company uses WAR as the standard deployment mechanism, it might be a good idea to reuse it. You don't even need to write some management functions like remote shutdown because Tomcat already provides them. All you need to do is to make sure all resources are freed up when undeployed.
Some people might not like this approach though. Ideally, there should be a common infrastructure for deploying and managing whatever application (aka microkernel), where even Tomcat is deployed as a module and the microkernel manages WAR directly instead Tomcat does. But that's a long way to go.
It makes terrific sense. We in fact run a Java email server in Tomcat.
Tomcat has some huge advantages for housing an application:
The daemon scripts are already written for you
Tomcat allows hot deployment (so long as you're not using hibernate :) )
At some point you may need either an Admin UI or Admin API
Lots and lots of tools to monitor Tomcat which means free monitoring of your app.
Now with Netty, Mina, or any event driven network technology you will not be able to use most MVC frameworks. In fact you will not be able to use most Java enterprise frameworks because many things rely on a thread per request (transactions, security, etc...).
Do not start anything in Tomcat, it is very inconvenient, and this has a lot of pain issues. Just embed Tomcat (or Jetty) inside your application and run your application as plain java process.
I need to start a copy of a Rails app from within Java. I would favor a lightweight HTTP server, as our installations will have a very small userbase (1-10, 10 being a huge installation).
My design I am aiming for is for a single process, with the web interface written in Rails - running on JRuby in a background thread of the main server written in Java.
Any tips on starting up Rails in this way? I very much don't want a separate Tomcat server running.
Thanks!
You could just create war files for every installation (google for "warbler") and serve them through one tomcat, or use jetty for each installation (which can be a little more lightweight than tomcat, depending on your configuration).
As far as I know, you can even run script/server via jruby (which starts webrick through jruby).
The simplest way that springs to mind is to make a shell call like
jruby script/server
... from you Java app.
We have had a web application product for several years, and used Tomcat to deploy it under Windows as it registers itself as a Windows service so it starts and stops automatically.
We may now happen to need more Java EE facilities than is provided by Tomcat (we are very tempted by the Java EE 6 things in the container) so the question is which Open Source Java EE containers work well as Windows services. Since Glassfish is the only Java EE 6 implementation right now, it would be nice if it works well, but I'd like to hear experiences and not just what I can read from brochures. If not, what else do people use?
EDIT: This goes for web containers too, and not just Java EE containers. We will probably keep the necessary stack included until we find the right container and it gets Java EE 6 support.
EDIT: I want this to work as distributed. I'm not interested in manually hacking wrappers etc., but want the installation process to handle the creation and removal of the service.
EDIT 2012: It turned out that the Windows installer for Glassfish can install as a service (requires .NET). Component web site http://kenai.com/projects/winsw. Has proven very robust.
We use Tomcat as a service. We have also used JBoss as a service.
It is possible to run GlassFish as a service.
It is also worth noting that most of the commercial Java EE containers can also run as a service. In particular, I know that all of the following can be run as a service, since we have set them up in that way:
Netweaver
WebLogic
WebSphere
In fact I think you would be hard pressed to find a Java EE container that could not be run as a service, since you could always use the Java service wrapper to wrap any java program as a service.
Since it was mentioned in another answer that you might also be interested in web servers running as services, it is probably worth pointing out that the big two on Windows, IIS and Apache, can both be run as services.
Edit: Since you edited to ask specifically about Java EE containers that contain installers that install the windows service:
Tomcat
JBoss
Netweaver
WebLogic
WebSphere
There are probably others, but these are the only ones that I have used.
There is Platform Services Support in GlassFish v3 which can interact with Solaris/OpenSolaris SMF and Windows Services. To my knowledge, it just works.
I use Caucho's Resin under windows, it comes with its own service installer which works quite well for me.
We use JBoss and it runs perfect as a service, no problems so far. We even have loaded the servers with ssh acces so we can remotely restart the services if we want.
I've used Glassfish (Version 2 though) as a Windows service. While it does take some work to get things installed, once set up, it worked pretty well. We used it in a production environment, and our set up consisted of a two node cluster (so we had to set up a domain, and two nodes (on two different machines)).
If I recall correctly, my biggest challenge was trying to use sc, and figuring out its funky escape sequences.
Another thing to look at is Hudson. I've always been impressed with how it installs itself as a Windows service. You may want to have a look at how they do it. They use Winstone as their embded servlet engine though, which as far as I know, is not EE 6 compliant.
I am fairly comfortable with standalone Java app development, but will soon be working on a project using a Java EE application server.
Does anyone know of a straightforward how-to tutorial to getting a hello-world type application working in an application server? I'm (perhaps naievly) assuming that the overall approach is similar between different frameworks, so I'm more interested in finding out the approach rather than getting bogged down in differences between the different frameworks.
If you are not aware of a good guide, then could you post bullet-point type steps to getting a hello-world running?, i.e.
Download XX
Write some code to do YY
Change file ZZ
Other steps...
Note: Just because I have a windows machine at home, I would prefer to run if this could be run on windows, but in the interest of a better answer, linux/mac based implementations are welcome.
I would choose JBoss AS or GlassFish for a start. However I'm not sure what you mean by Java EE "Hello World". If you just want to deploy some JSP you could use this tutorial (for JBoss):
http://www.centerkey.com/jboss/
If you want to get further and do the EJB stack and/or deploy an ear-file, you could read the very good JBoss documentation:
Installation Guide
Getting started
Configuration Guide
In general you could also just do the basic installation and change or try the pre-installed example applications.
I currently have JBoss installed (on windows). I develop with Eclipse and use the Java EE server integration to hot deploy or debug my code. After you get your first code running you realy should have a look at the ide integration since it makes development/deploy roundtrips so much faster.
The JavaEE (they dropped the 2) space is pretty big. A good tutorial to start is the one from Sun. For a simple hello world application, the web container only would suffice. A well known servlet jsp container is tomcat. See here for installation instructions. Try installing it with eclipse and create a web project. This will generate some files for you that you can look at and edit. Also starting and stopping the application server is simpler.
Another option is to get Oracle JDeveloper (free to download and use - it's a full featured IDE that includes some neat extras like the SQL workbench and BPEL designer).
As a learning tool, it is quite good, not only for the tutorials available from Oracle, but it includes a range of "cue-card" lessons in the tool itself to teach many common techniques.
cue card view http://tardate.heroku.com/images/jdev-cuecards.jpg
If you haven't gone near NetBeans in a while its catching up with Eclipse very fast and worth a look, especially when starting Java EE.
Version 6.x installs Tomcat and/or Glassfish for you and then provides wizards to create/deploy/redeploy applications.
The initial tutorial on Web Applications is here and a more complex example here.
As JeroenWyseur puts it, Java EE is a fairly big space. In addition to what he said, you should try to get more details of what exactly you'll be doing: servelts & co, EJB (entity, session, message beans?) and try to get familiar with that.
It should be clear for you that your code runs in a managed environment, which imposes a lot of constraints. in order to make sure you understand what happens you should get familiar with the concept of deployment. Then, if you do EJBs, transaction management is important too. If you don't understand exactly what happens when a bean or a servlet is deployed, how transactions are managed, how beans are invoked, you're going to have a hard time.
A book that helped me a lot back in the time is Mastering EJB, by Ed Roman.
Also, getting familiar with RMI will help you understand EJBs.