We have two different Java web apps named foo.war and bar.war and we want to deploy these on Jetty server
Jetty is running on 8080 port on the machine
Is it possible simultaneously run two apps on same port ? If no what are the alternatives to run multiple web apps on same jetty server
Thanks
You can run as many web applications as you want in a servlet container. They just need different context roots.
Let's say you have abc.war and def.war. If you deploy both, by default you can access them through http://localhost:8080/abc and http://localhost:8080/def.
Since this usually looks ugly, it's a good idea to put a reverse proxy in front of your Servlet container. This will allow you to have for example 2 different domains foobar.com and xipbaz.com that will then be routed to different applications, even if they're all on the same server.
Related
I have two applications, can I run them on one port 8080? I am currently running them on different ports.
This would be the equivalent of putting a proxy in-front of 2 apps anyway. You could deploy 2 different apps on a Servlet Container like Tomcat, but arguably you could consider Tomcat an app, but it's just perspective. The only reason you would want to do that is to share resources to minimize application runtime footprints, which nobody cares about anymore anyway.
If you use Tomcat then the answer is yes. When deploy, just choose the same Tomcat instance for both apps and voila. However it is advised to use multiple Tomcat instances and separate ports for different applications.
In the past when a new webapp or set of services was to be deployed, it was common practice to be given a new vm with tomcat installed on to deploy to. With my current position the client is only giving me one linux instance to deploy several webapps to. (Small internal usage, 0 scaling. Deploying to a single AWS EC2 linux machine)
The applications are required to be given unique domains. ie app1 and app2 could be mapped to smallapp1.com:8080/app1/login and smallerapp2.com:8080/app2/login (ports are for example only and not a requirement)
I currently have two installations of tomcat8 running on the instance and each application is deployed to a unique tomcat install and running on different ports. (one is 8080 and the other 8081).
If I were to want to deploy a handful of other small applications would I be better off using individual tomcat installations or should I be using Virtual Hosting?
I am new to deployment. In the past I was handed a deployment destination and procedure. In the new position I was simply given credentials to a single instance. I am not sure what is better practice or in which situation which is better than another. If it matters, each application is only ever going to be used by a maximum of 20 users at the same time.
TL;DR Using multiple installations of tomcat on the same instance or using the same tomcat installation to host multiple applications.
Virtualhosts is a better option because you are not bloating the server with several installations that could conflict with each other, and you are to take 1 port for each instance of tomcat.
Keep in mind that tomcat is a better solution for Java web applications, if you are not running servlets or JSPs you are better off using Apache Http server.
I currently have a Spring application that can be run or debugged locally via embedded Tomcat (through spring-boot), or packaged into a war file and deployed as an app. It has some RESTful services, which are consumed by a single-page-application.
Right now, all of the static assets, including the front-end javascript, are contained in the /src/main/webapp directory. This allows rapid development of both the back-end (embedded tomcat can restart quickly for back-end changes), AND front-end code (any changes made to html/javascript/css can be picked up with just a refresh while the app is running in embedded mode).
However, for various reasons outside my control, I am going to have to separate the front-end and the back-end into separate projects which will be developed and deployed separately. This presents a problem - how do I get a local development environment setup with the same kind of rapid development of both the back-end and the front-end on the same development machine? The front-end servlet and the back-end servlet can't run on the same port, and if I set them up to use different ports, then the browser won't let the front-end javascript make requests to the back-end servlet without setting up CORS, which I'd like to avoid.
Eventually, the two apps will either be deployed to the same Tomcat instance, or else a router will route traffic to them such that they're still on the same domain, so that they can talk to each other without CORS. But that doesn't help me for local development.
I ended up using nginx: http://nginx.org/en/docs/windows.html
I added the following to my conf/nginx.conf:
location /site1/ {
proxy_pass http://localhost:8081/;
}
location /site2/ {
proxy_pass http://localhost:8080/;
}
And configured my two apps (site1 and site2) to run on ports 8081 and 8080 respectively. This effectively simulates the shared tomcat deployment (one domain/port) while using two running instances of tomcat embedded (on two ports).
"The front-end servlet and the back-end servlet can't run on the same port"
Yes they can, tomcat can run several servlets, indeed it can run several applications on the same instance. Just make sure the apps can be differentiated at the URL level
i.e.
server.com/backend_app/
server.com/frontend_app/
Maybe I'm not understanding your question fully......
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 currently developing an application for some researchers in my university.It's a small java program that you can use by command line. The next step is to package that program and deploy it to an application server. Some clients program will submit requests to the server who will call the tool that I wrote. Lately, we will add more tools to the server and he has to dispatch the requests to the right tool.
Which application server fits my needs ? I have looked for Tomcat, Jetty and Glassfish but it seems that they are only used for web application.
Is it possible to use those servers in some context different from web context? Which package archive should i use (jar, war) ?
Any advice?
Some clients program will submit requests to the server who will call the tool that I wrote.
The big question is what server-side technology and what communication protocol can you use between the clients and the server. You basically have two major options: HTTP and web services (in that case, consider using either JAX-WS or JAX-RS) or RMI-IIOP and EJBs (in that case, you'll have to use a Java EE compliant server like GlassFish).
I have looked for Tomcat, Jetty and Glassfish but it seems that they are only used for web application.
Not really. As I said, they can also be used for web services oriented applications. And GlassFish can be used for EJBs applications.
Which package archive should i use (jar, war)
The packaging will depend on the type of application you'll write, it's not something that you choose upfront, it's just a consequence. EJBs are packaged in an EJB JAR and typically deployed inside an EAR; Servlet based web services are deployed inside a WAR.
You really need to think about what technology to use first (with the current level of detail, I can't provide more guidance).
Do you even need an application server? There's nothing stopping you from adding the necessary network bindings and deploying it on its own.
Of the servers you mention, you've got 2 different categories: servlet containers and full-stack Java EE servers
Tomcat and Jetty are servlet containers. That doesn't mean that you can only do web stuff with them and you could manually add the required libraries to get a full Java EE server.
Glassfish is a full-stack Java EE server and can be compared with JBoss (both are open source) or the commercial rivals Weblogic and Websphere.
Sometimes this question is simple as the environment you are working in mandates a particular flavour of app server. You should check this first.
If you're not forced to use an app server, I'd ask why you think you need to use an app server?
I don't see why you would want to use tomcat, glassfish or jetty for a command line program.
If it's command-line based, and you want it to run server-side, you could write a little program that allows users to, for instance, telnet to your server, which in turn starts the CLI-application in question, and relays input / output to the client.
You may also want to look into Java Webstart, which makes deployment of new versions a breeze.
Actually we can't answer with so few elements.
- What are you planning to do
- With what technologies
- Where are you planning to host your application (have you got budget?)
- In which language are written the clients (even the future ones)?
- Could clients be on mobile phones (add some technlogy constraints...)
....
It would also be great to know what kind of request the clients will do, and what kind of response the server will provide...
Actually with what you tell us, all those application servers can do what you want...
I have looked for Tomcat, Jetty and
Glassfish but it seems that they are
only used for web application
You could even make a webapplication (servlet) and on the clientside use a httpclient to call that servlet... there are so many options :)
vive Paris!