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.
Related
Well, I've been trying to deploy war files on tomcat 8 DIY that I installed, but I couldn't find any useful tutorials, they all give examples with an OpenShift Tomcat 6/7 with git clone containning src folder and pom.xml. But DIY git clone contain misc and diy folders only.
I was able to deploy ode.war Apache server and axis2 through the web browser => ManagerApp, but it doesn't work with webServices it gives me 404 error.
Besides I need to deploy a BPEL process which cannot be rendered in a war file, is there a way to deploy a folder on ode that i've just installed it contain the processes folder pretty much like webapp in tomcat
Or should I switch to OpenStack, is it more easyier especially that all of this is just for test. Thank's
You are really talking about two different technologies there, OpenShift is a PaaS, and OpenStack is a way to control large pools of compute, storage, and networking resources throughout a datacenter.
If you really want to write Web Applications using Java, try using one of the application servers like JBoss, JBoss EAP, or WildFly, instead of using a servlet container (Tomcat).
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 created a jsp file which will give an output in JSON format using java class and servlet, i am new to java and i don't have idea about the deployment of jsp file. Can anyone suggest me how to do it? I used to develop an asp.net web application in which there was a specific option available which called " publish project", but i cant find in eclipse.
I already have a php server in which i have uploaded few php files, can i use the same server to upload this file?
Currently, my application is running fine on localhost.
Please help me with this matter and thank you for your time.
To publish your project in Eclipse:
Right click your project
Export
Under Web > Choose WAR
Then just follow the instructions and your good to go.
It is done as a component of a WAR (Web Application Archive) file.
Upon deployment, JSP files are processed by the Servlet container. The processing effectively turns them into Servlets, such that the plain text of the JSP becomes println statements in the response of the Servlet, and the embedded Java code in the JSP becomes regular Java code in the Servlet.
The packaging details are covered in detail in the JEE7 tutorial, although earlier tutorials don't differ much in the details.
i assume you are using tomcat in your php? you can use tomcat or glassfish server to deploy your application. you just need the .war file of your application and upload it to the admin page of tomcat or glassfish server.
It should be in .war file format
Here are few links which can help you in building it from eclipse, link1, link2.
For deployment, there should be a server -- tomcat / glassfish / jboss which can provide platform to execute .war files.
IDEs and .war files are great productivity tools, but I'm of a mind that you need to understand how these things work from the command line. I'm using Apache Tomcat running on a Raspberry Pi as a development server. I developed my .jsp and then just copied to where it needed to be. In this example login.jsp needs to be in the root folder of an app called SEM. So, just copy it there and access it via its URL.
sudo cp login.jsp $CATALINA_BASE/webapps/SEM
http://localhost:8080/SEM/login.jsp
Didn't even have to restart Tomcat. :)
I have a Java EE application, running under WebLogic 10.3.5 and Java 6.
I used to have a pdf help file, embedded in my war file, but I need to extract it from there and put it in an external directory (it can be in my same WebLogic domain directory).
I tried to put it in my WebLogic domain and then to < a href > it, but it seems that browsers have limitation and for security reason will not allow to download local file with a href or javascript.
This used to work only on a static HTML file saved on my computer but one the HTML page is deployed on the server, it seems not be possible.
Any idea how I can externalize my help.pdf file from my war file?
#limc is right
you should put this static file outside of Weblogic altogether as a file on an Apache web server
However, in Weblogic there is a feature of virtual directory mapping which allows you to declare a folder outside of the weblogic domain as a content store for any static stuff.
http://docs.oracle.com/cd/E11035_01/wls100/webapp/weblogic_xml.html#wp1039396
This entry goes in WEB-INF/weblogic.xml
<virtual-directory-mapping>
<local-path>c:/usr/mypdfs</local-path>
<url-pattern>/pdf/*</url-pattern>
</virtual-directory-mapping>
Although some application servers allow a Java EE app to reference a file outside the web container, in reality, your web app shouldn't have any knowledge about anything outside the web container, and as you have mentioned, it is indeed a huge security concern.
Depending on what you are trying to accomplish with this PDF file, if you merely want to expose this file on the web, do what #duffmo said and it will work fine. If you want the flexibility to modify this PDF file frequently without recreating the war file again and again, you may want to consider hosting this PDF file in some HTTP web server (Apache2, IIS, etc) and now you reference that link from your web app.
You need to put it at the root of your web context, in exactly the same place as HTML pages. Your web server will be able to find it there.
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.