deploy war file in tomcat server - java

I have copied the sample.war file in webapps directory of tomcat.
I can acess localhost:8080.
deploying of wars is automatic by default -i have checked my webapps folder for an extracted folder "sample"
but it is not extracted.why the war file is doesn't extracted.please give me solution for this.

Delete that war file from webapps/ directory. Then open link http://localhost:8080/ in your web browser. Click Tomcat Manager then enter user name and password. In next page you can see one option called "WAR file to deploy". Select your war file from there and click "deploy" button.
If you want auto deployment when you copy files to webapp/ directory. Then make sure that you server.xml file contains the following values:
autoDeploy="true"
unpackWARs="true"
Just search these values in your server.xml file and edit values as shown above
For more info see Deploy A New Application from a Local Path.

In general this happens when you have 2 Tomcats. If CATALINA_HOME is referring to Tomcat-A and you are trying to run Tomcat-B from Tomcat-B/bin/startup.bat. It will run Tomcat-A. Hence your war which you are trying to deploy in Tomcat-B will not be extracted as Tomcat-A is running in actual.

Related

Cannot see Tomcat homepage( http://localhost:8080) when starting it from eclipse. But it loads when I start it from tomcat bin directory. Any idead?

I have added tomcat 7 to my eclipse.
When I start the server it gets started successfully(shows the message in console) but when I hit the URL http://localhost:8080 it says "404 resource not found".
Strange thing is when I go to Tomcat bin directory and start it through start.bat, the same url http://localhost:8080 shows the tomcat homepage in browser without any issue.
Any idea? Help is appreciated.
You need to be aware of two directory trees with Tomcat : TOMCAT_HOME and TOMCAT_BASE.
TOMCAT_HOME contains binary related data and can be shared by many running Tomcat instances (it contains jar, dll, exe and other non-contextual data).
TOMCAT_BASE specifies configuration files (ie catalina.properties, server.xml, context configurations), webapp directories and further files such as specific librairies if required.
When running Tomcat from his installation directory: TOMCAT_HOME and TOMCAT_BASE are set to same location. Then, Tomcat serves ${TOMCAT_HOME}\webapps directory. The special ROOT context let serve the root path and by default contains a simple webapp (browse ${TOMCAT_HOME}\webapps\ROOT for more information).
When running Tomcat from Eclipse, Eclipse will setup two directories:
with editable configuration (generally goes under ${WORKSPACE}\Servers\${SERVER_NAME}-conf)
with deployed files from last describe directory, served context configuration, deployed context and some other working files such as log and work directories.
This last directory generally goes under your workspace metadata but you can edit it from the server editor. And Eclipse uses this directory as TOMCAT_BASE. To this directory, Eclipse doesn't deploy the default ROOT webapp neither other default ones (docs, examples, host-manager and manager). If necessary you can add them from the server configuration directory (first one described).

How to access folder in tomcat server using relative path of it?

I have one folder which has some PDF files which is used by my application, but when I include this folder in my war file , the size of war file increase to GBzz , so I thought of keeping this folder in some server location , build and deploy the war without the folder which will have the relative path of this folder , can any one help me on this? I am not sure how to do configuration for this to read the folder ?I am using tomcat server.
The easiest way starting from Tomcat 7 is to configure alias paths i.e. paths on the disk that will be aliased in Tomcat. Check this section in the guide for aliases attribute.
You want something like this in your server.xml:
<Context docBase="AppName" path="/appname" aliases="/pathPdf=c:\pdfs"/>
In case you're on an older Tomcat, your best bet is to setup a servlet that will serve files from the desired external location.

Deploy JSP webproject to tomcat [duplicate]

I have copied the sample.war file into the webapps directory of Tomcat, and I can access localhost:8080.
Now how will Tomcat deploy it, I mean do I need to open it in browser? How can I access the application?
You can access your application from: http://localhost:8080/sample
Deploying or redeploying of war files is automatic by default - after copying/overwriting the file sample.war, check your webapps folder for an extracted folder sample.
If it doesn't open properly, check the log files (e.g. tomcat/logs/catalina.out) for problems with deployment.
step-1. here I'm deploying pos.war First go to tomcat webapps folder and paste it
step-2. go to tomcat->bin folder start tomcat by clicking startup.bat
step-3. go to browser write localhost:port/project name eg. localhost:8080/pos (here my tomcat run on port 8080)
Done....
You just need to put your war file in webapps and then start your server.
it will get deployed.
otherwise you can also use tomcat manager a webfront to upload & deploy your war remotely.
Manual steps - Windows
Copy the .war file (E.g.: prj.war) to %CATALINA_HOME%\webapps ( E.g.: C:\tomcat\webapps )
Run %CATALINA_HOME%\bin\startup.bat
Your .war file will be extracted automatically to a folder that has the same name (without extension) (E.g.: prj)
Go to %CATALINA_HOME%\conf\server.xml and take the port for the HTTP protocol. <Connector port="8080" ... />. The default value is 8080.
Access the following URL:
[<protocol>://]localhost:<port>/folder/resourceName
(E.g.: localhost:8080/folder/resourceName)
Don't try to access the URL without the resourceName because it won't work if there is no file like index.html, or if there is no url pattern like "/" or "/*" in web.xml.
The available main paths are here: [<protocol>://]localhost:<port>/manager/html (E.g.: http://localhost:8080/manager/html) and they have true on the "Running" column.
Using the UI manager:
Go to [<protocol>://]localhost:<port>/manager/html/ (usually localhost:8080/manager/html/)
This is also achievable from [<protocol>://]localhost:<port> > Manager App)
If you get:
403 Access Denied
go to %CATALINA_HOME%\conf\tomcat-users.xml and check that you have enabled a line like this:
<user username="tomcat" password="tomcat" roles="tomcat,role1,manager-gui"/>
In the Deploy section, WAR file to deploy subsection, click on Browse....
Select the .war file (E.g.: prj.war) > click on Deploy.
In the Applications section, you can see the name of your project (E.g.: prj).
In addition to the ways already mentioned (dropping the war-file directly into the webapps-directory), if you have the Tomcat Manager -application installed, you can deploy war-files via browser too. To get to the manager, browse to the root of the server (in your case, localhost:8080), select "Tomcat Manager" (at this point, you need to know username and password for a Tomcat-user with "manager"-role, the users are defined in tomcat-users.xml in the conf-directory of the tomcat-installation). From the opening page, scroll downwards until you see the "Deploy"-part of the page, where you can click "browse" to select a WAR file to deploy from your local machine. After you've selected the file, click deploy. After a while the manager should inform you that the application has been deployed (and if everything went well, started).
Here's a longer how-to and other instructions from the Tomcat 7 documentation pages.
There are two ways:
Either you can do hot deployment (Hot deployment means deploying when server is running/up).
Or you can do cold deployment (Cold deployment means deploying when server is stopped).
Just use tomcat manager console for console deployment or simply copy and paste your application in webapp folder of your server's tomcat_home directory.
Note: Make sure if your war file size is more than 52 MB (the default configuration value),
you need to make two little changes in web.xml file of Manager application of your webapp folder(Manager application is provided by Apache tomcat by default upon installing the server).
Go to the web.xml of the manager application (for instance it could
be under /tomcat7/webapps/manager/WEB-INF/web.xml.
Increase the max-file-size and max-request-size values in web.xml file:
<multipart-config>
<!– 50MB max –>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
Increase the size by putting the values for <max-file-size> and <max-request-size> according to your requirement.
This has been working for me:
Create your war file (mysite.war) locally.
Rename it locally to something besides .war, like mysite.www
With tomcat still running, upload mysite.www to webapps directory.
After it finishes uploading, delete the previous version mysite.war
List the directory, watching for the directory /mysite to disappear.
Rename mysite.www to be mysite.war
List the directory, watching for the new /mysite to be created.
If you try uploading the new file as a war file, with tomcat still running, it will attempt to expand it before it is all there. It will fail. Having failed, it will not try again. Thus, uploading a www file, then renaming it, allows the whole war file to be present before tomcat notices it.
Hint, don't forget to check that the war file's owner is tomcat (Use chown)
If you installed tomcat7 using apt-get in linux then, deploy your app to /var/lib/tomcat7/webapps/
eg.
sudo service tomcat7 stop
mvn clean package
sudo cp target/DestroyTheWorldWithPeace.war /var/lib/tomcat7/webapps/
#you might also want to make sure war file has permission (`777` not just `+x`)
sudo service tomcat7 start
Also, keep tailing the tomcat log so that you can verify that your app is actually making peace with tomcat.
tail -f /var/lib/tomcat7/logs/catalina.out
The deployed application should appear in http://172.16.35.155:8080/manager/html
For deploying the war file over tomcat,
Follow the below steps :
Stop the tomcat. powershell->services.msc->OK->Apache Tomcat 8.5->stop(on left hand side).
Put the .war file inside E:\Tomcat_Installation\webapps i.e. webapps folder i.e. put.war (put.war is just an example)
After starting the tomcat(to start tomcat powershell->services.msc->OK->Apache Tomcat
8.5->start )
you will get one folder inside E:\Tomcat_Installation\webapps**put**
In this way you can deploy your war file in Apache Tomcat.
1.Generate a war file from your application
2. open tomcat manager, go down the page
3. Click on browse to deploy the war.
4. choose your war file.
There you go!
The application name goes into the context of your tomcat deployed URL,
eg. http://localhost:Port/applicationName.
If your application name is simple then, it should be http://localhost:8080/sample.
By default, Port is 8080, but if you wish to change it, or want to know the port where tomcat is running, simply go to server.xml file in <tomcat-apache-dir>/conf/server.xml, there you can find port & change,
eg. <Connector port="8080" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/>
If anything goes wrong, check the log files (e.g. <tomcat-apache-dir>/logs/catalina.out)
Perform the following steps:
Stop the Tomcat
Right Click on Project and click on "Clean and Build"
Go to your project Directory and inside Dist Folder you will get war file that you copy on your tomcat
webApp Folder
Start the tomcat
automatic war file extract and run your project
I followed the instruction in the following link, it works for me.
http://www.coderanch.com/t/487178/Tomcat/war-file-show-load
Stop Tomcat
Delete all the logs in tomcat/logs and all files in tomcat/conf/Catalina/localhost
Remove the war file and the directory it created (if it did) from tomact/webapps
Start Tomcat
While watching the logs, copy the war file to the webapps directory again
After this, keep an eye on the catalina.xxxx-xx-xx.log to find out the issue.

Getting the Path to WEB-INF on Openshift Tomcat 6 - JBoss EWS 1.0

I previously used the following to get my context path on Tomcat-5.0.28 and earlier:
String context_path = context.getRealPath("/WEB-INF/");
This worked to return the path to that folder.
But on OpenShift (Tomcat 6 - JBoss EWS 1.0) this returns
/var/lib/openshift/53.*context_id_here*..18/jbossews/null
The null should be:
work/Catalina/localhost/_/WEB-INF
How can I get the path to the WEB-INF folder on OpenShift using JBOSS/Tomcat?
A little background information: When I ran this struts webapp on my own Tomcat server, I deployed a appname.war file in the webapps directory and waited for it to expand (since I had set that option in the server.xml file). Then I move a folder to webapps/appname/ folder with xml files I need to read and write to for my app to work. On OpenShift I used jar xvf appname.war to extract the war file by hand (because that's the default and I don't know how to change it), and then moved the files folder (from the same directory as the war file in my folder after a git add and push) to work/Catalina/localhost/_/WEB-INF/
This is causing a NullPointerException for me when trying to use that path as shown above.
I think you should be using something like getServletContext or getRealPath, and reading it from the web root instead of trying to find the file on the physical disk. That way your war file can run anywhere without issue. Try looking up both of those and see if one fits your use case.

How to deploy a war file in Tomcat 7

I have copied the sample.war file into the webapps directory of Tomcat, and I can access localhost:8080.
Now how will Tomcat deploy it, I mean do I need to open it in browser? How can I access the application?
You can access your application from: http://localhost:8080/sample
Deploying or redeploying of war files is automatic by default - after copying/overwriting the file sample.war, check your webapps folder for an extracted folder sample.
If it doesn't open properly, check the log files (e.g. tomcat/logs/catalina.out) for problems with deployment.
step-1. here I'm deploying pos.war First go to tomcat webapps folder and paste it
step-2. go to tomcat->bin folder start tomcat by clicking startup.bat
step-3. go to browser write localhost:port/project name eg. localhost:8080/pos (here my tomcat run on port 8080)
Done....
You just need to put your war file in webapps and then start your server.
it will get deployed.
otherwise you can also use tomcat manager a webfront to upload & deploy your war remotely.
Manual steps - Windows
Copy the .war file (E.g.: prj.war) to %CATALINA_HOME%\webapps ( E.g.: C:\tomcat\webapps )
Run %CATALINA_HOME%\bin\startup.bat
Your .war file will be extracted automatically to a folder that has the same name (without extension) (E.g.: prj)
Go to %CATALINA_HOME%\conf\server.xml and take the port for the HTTP protocol. <Connector port="8080" ... />. The default value is 8080.
Access the following URL:
[<protocol>://]localhost:<port>/folder/resourceName
(E.g.: localhost:8080/folder/resourceName)
Don't try to access the URL without the resourceName because it won't work if there is no file like index.html, or if there is no url pattern like "/" or "/*" in web.xml.
The available main paths are here: [<protocol>://]localhost:<port>/manager/html (E.g.: http://localhost:8080/manager/html) and they have true on the "Running" column.
Using the UI manager:
Go to [<protocol>://]localhost:<port>/manager/html/ (usually localhost:8080/manager/html/)
This is also achievable from [<protocol>://]localhost:<port> > Manager App)
If you get:
403 Access Denied
go to %CATALINA_HOME%\conf\tomcat-users.xml and check that you have enabled a line like this:
<user username="tomcat" password="tomcat" roles="tomcat,role1,manager-gui"/>
In the Deploy section, WAR file to deploy subsection, click on Browse....
Select the .war file (E.g.: prj.war) > click on Deploy.
In the Applications section, you can see the name of your project (E.g.: prj).
In addition to the ways already mentioned (dropping the war-file directly into the webapps-directory), if you have the Tomcat Manager -application installed, you can deploy war-files via browser too. To get to the manager, browse to the root of the server (in your case, localhost:8080), select "Tomcat Manager" (at this point, you need to know username and password for a Tomcat-user with "manager"-role, the users are defined in tomcat-users.xml in the conf-directory of the tomcat-installation). From the opening page, scroll downwards until you see the "Deploy"-part of the page, where you can click "browse" to select a WAR file to deploy from your local machine. After you've selected the file, click deploy. After a while the manager should inform you that the application has been deployed (and if everything went well, started).
Here's a longer how-to and other instructions from the Tomcat 7 documentation pages.
There are two ways:
Either you can do hot deployment (Hot deployment means deploying when server is running/up).
Or you can do cold deployment (Cold deployment means deploying when server is stopped).
Just use tomcat manager console for console deployment or simply copy and paste your application in webapp folder of your server's tomcat_home directory.
Note: Make sure if your war file size is more than 52 MB (the default configuration value),
you need to make two little changes in web.xml file of Manager application of your webapp folder(Manager application is provided by Apache tomcat by default upon installing the server).
Go to the web.xml of the manager application (for instance it could
be under /tomcat7/webapps/manager/WEB-INF/web.xml.
Increase the max-file-size and max-request-size values in web.xml file:
<multipart-config>
<!– 50MB max –>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
Increase the size by putting the values for <max-file-size> and <max-request-size> according to your requirement.
This has been working for me:
Create your war file (mysite.war) locally.
Rename it locally to something besides .war, like mysite.www
With tomcat still running, upload mysite.www to webapps directory.
After it finishes uploading, delete the previous version mysite.war
List the directory, watching for the directory /mysite to disappear.
Rename mysite.www to be mysite.war
List the directory, watching for the new /mysite to be created.
If you try uploading the new file as a war file, with tomcat still running, it will attempt to expand it before it is all there. It will fail. Having failed, it will not try again. Thus, uploading a www file, then renaming it, allows the whole war file to be present before tomcat notices it.
Hint, don't forget to check that the war file's owner is tomcat (Use chown)
If you installed tomcat7 using apt-get in linux then, deploy your app to /var/lib/tomcat7/webapps/
eg.
sudo service tomcat7 stop
mvn clean package
sudo cp target/DestroyTheWorldWithPeace.war /var/lib/tomcat7/webapps/
#you might also want to make sure war file has permission (`777` not just `+x`)
sudo service tomcat7 start
Also, keep tailing the tomcat log so that you can verify that your app is actually making peace with tomcat.
tail -f /var/lib/tomcat7/logs/catalina.out
The deployed application should appear in http://172.16.35.155:8080/manager/html
For deploying the war file over tomcat,
Follow the below steps :
Stop the tomcat. powershell->services.msc->OK->Apache Tomcat 8.5->stop(on left hand side).
Put the .war file inside E:\Tomcat_Installation\webapps i.e. webapps folder i.e. put.war (put.war is just an example)
After starting the tomcat(to start tomcat powershell->services.msc->OK->Apache Tomcat
8.5->start )
you will get one folder inside E:\Tomcat_Installation\webapps**put**
In this way you can deploy your war file in Apache Tomcat.
1.Generate a war file from your application
2. open tomcat manager, go down the page
3. Click on browse to deploy the war.
4. choose your war file.
There you go!
The application name goes into the context of your tomcat deployed URL,
eg. http://localhost:Port/applicationName.
If your application name is simple then, it should be http://localhost:8080/sample.
By default, Port is 8080, but if you wish to change it, or want to know the port where tomcat is running, simply go to server.xml file in <tomcat-apache-dir>/conf/server.xml, there you can find port & change,
eg. <Connector port="8080" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/>
If anything goes wrong, check the log files (e.g. <tomcat-apache-dir>/logs/catalina.out)
Perform the following steps:
Stop the Tomcat
Right Click on Project and click on "Clean and Build"
Go to your project Directory and inside Dist Folder you will get war file that you copy on your tomcat
webApp Folder
Start the tomcat
automatic war file extract and run your project
I followed the instruction in the following link, it works for me.
http://www.coderanch.com/t/487178/Tomcat/war-file-show-load
Stop Tomcat
Delete all the logs in tomcat/logs and all files in tomcat/conf/Catalina/localhost
Remove the war file and the directory it created (if it did) from tomact/webapps
Start Tomcat
While watching the logs, copy the war file to the webapps directory again
After this, keep an eye on the catalina.xxxx-xx-xx.log to find out the issue.

Categories

Resources