I want to serve two servlets on different port, something like
http://localhost:8888/servlet1
http://localhost:9999/servlet2
These servlets are part of one war file. I found a way to do as explained in this blog. But I am not using embedded jetty. In my case its a separate jetty installation. I dump my application war file inside webapp directory of jetty. I have configured servlet mappings in web.xml file, which is inside war. I have followed the jetty documentation to create connector and virtual hosts by configuring xml files as described there. But still I am not able to understand how/where would I pass in the configuration saying serve servlet1 from 8888 and servlet2 from 9999. Anyone has done this before through xml files?
Related
I've created a dynamic web application and i'd like to deploy it with glassfish. I've successed build my sources to MyProject.jar. But when i deployed it, the following error displayed:
remote failure: Archive type of /home/davenlin/MyProject/build/MyProject.jar was not recognized
My project is just a normal Restful application, not ejb application, so i don't know if i must generate a MyProject.war instead of MyProject.jar.
Please help me. Thanks !
Okay, because my comment was rather unexplanatory:
Web applications are handled by application servers or servlet containers.
Both do quiet a lot of work for you and web applications are not comparable to
desktop or standalone java applications. While your standalone applications are deployed as jar - files and then executed by the JVM, web applications are
executed by the container (application server / servlet container).
So this does require your application to provide additional configuration and affords the archive itself to have a different structure.
So even if you are just exposing some web services to build a restful application, your application server will do things for you such as
forwarding requests to the right classes, translate query and post parameters into java - objects accessable by your own classes respectivly your own objects and returning your response to the clients.
The interesting thing about it is:
The additional files in the web - archive are usually xml - files and web - related files such as html, css, js.
So this does not distinguish war's from jar's as you can also package additional resources within a jar.
The basic but now obsolete requirement on a war - file is that it contains
a deployment descriptor (which is again is an xml - file)
to configure your application , its context and the relative url (more concrete : url - patterns) it uses , but as this requirement is obsolete someone may still think that this distinguishing is obsolete, too.
I have made an app using Tomcat as my server. It uses JSP pages and java servlets.
If I copy my webapp (the folder) to some other server, will it run? What are the requirements for it to work/not work?
EDIT: Thanks for the answers. One more thing, what if some of my code uses filepath, that originates from the bin folder of Tomcat. For eg: "../webapps/MyApp/WEB-INF/sample.txt"
Is the directory structure the same in all servers?
Java servlets and JSP are intended to be portable technologies. There is a servlet standard and a JSP standard. Any servlet container (such as Tomcat) that implements the version of the standard that your code uses should be able to run your code.
You should move your web application around by copying its web application archive (WAR) file, rather thsn the directory (the extracted content of the WAR).
Ofcourse it will run , there are many servers out there that support jsp/servlet . Most of them are free for development and some are paid for deployment. See this link for more info
For most of the containers (i am not sure for all but most of them) like Tomcat, Jetty, Resin etc, you don't need to modify the project. You can place your project war file in the webapps directory and the project will get deployed on starting the server.
I have some deployment model question for a Java EE web application. Currently we are deploying our web application as a WAR file in Tomcat 6. All the content is packaged with the WAR file including the static content like images, static html pages and so on. But i want to deploy these static content in a HTTP server and use the Application server only for retrieving the dynamic content. How do i split these things? Does any one has done any thing of this sort and have a good deployment model for my scenario. Help will be appreciated.
Is it a good idea to make 2 WAR files one with only static content and deploy that WAR in HTTP server and the rest as a different WAR file and deploy it in the Application server? But this approach will have impact on all the pages where the static content is currently referred and requires code changes which is very cumbersome since our project is Huge and the code based is very very big.
Any strategy and ideas are welcome.
This can be something interesting to do for performance reasons.
You should have separate deployment scripts / deployment files to do this.
Having multiple file/WAR/folder/scripts to deploy for one project is not an issue. We have the same thing when you have to deploy your WAR and to update your database.
I would have a WAR file and a folder with your static content to deploy.
Edit
Deploying the static content in a HTTP server depends on the server.
If you want to use Apache on a Linux server, you have to set up a Virtual Host.
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
DocumentRoot /www/domain
</VirtualHost>
In this example, you have the a virtual host that listens on 80 port, for any IP address and for the server name www.example.com. Then this is redirected to the /www/domain path.
You will find much more examples and configuration options in the documentation.
You can not deploy WAR file into HTTP server. A WAR is used for Java web applications it must be deployed into application server or servlet container (like Tomcat). I don't think that its a good idea to separate static content in a separate web application. If this is one project it should be one web application, besides:
A WAR file has a special folder structure and contains special files
in addition to JSP pages, Java servlets, Java classes, HTML pages etc.
which combined forms a Web Application.
You can hold your static contents in your one application and there is really nothing bad about it.
If your project is very huge and has a lot of files it is no problem, you just need to use the project structure like that, that it should be easily understandable and readable and the application server or servlet container will take care of deploying as many contents as there is.
Up to version 4, Tomcat has been quite slow in serving static content. This is why it was frequently recommended to split dynamic from static content and serve the latter using a regular web server (the book you mentioned was issued in 2002...). Recent Tomcat versions do not face this problem, thus you can IMHO refrain from splitting, which can be a nightmare for both organization and security.
For static resources, you might rather focus on configuring proper caching, so they will not be transferred more often than necessary.
I have got two java projects:
is a web service, which is running fine on Tomcat 6.
the other is a client developed using Play 1.2.4 framework and must be deployed on the same tomcat as that of the web service.
My problem is that when they are deployed as a war file on tomcat, client request URL's don't include the application context and thus the path could not be found.
I read as it is possible to make Apache a bridge for tomcat will solve the problem but don't know how to configure it.
Please help me out.
I think what you mean is that your UI, developed with Play, is deployed under a context like /myapp.
You have two options:
rename the WAR file to ROOT.war. Tomcat will deploy it to /
Use Apache as Proxy and implement a Redirect
Apache config would look like:
RedirectMatch "^/$" /myapp
ProxyPass /myapp http://tomcatserver:8080/myapp
We have a web application (Metro web services on tomcat) and need to handle properties to access remote systems.
Of course the properties are different in test and production environment.
We could deploy a properties file with the WAR file, but this would require manual steps after the deployment of the application. (editing after the deployment)
In other projects we had property files located in directories 'above' the deployed web application, to avoid that the property files are changed - but I'm not sure if this is a good design.
Which is the 'cleanest' way of handling server specific properties with tomcat web applications?
Define the settings in Tomcat's server.xml, then access them in your application with JNDI. See: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
Either put it directly it into WEB-INF/classes and if it is made to configure by non technical person then keep it in user.home/appName/