I'm new to deployment process. Kindly advice me.
I have created a WAR file in my development machine. Then in the server machine, I have installed Tomcat which is clean and new. Then I copied the WAR file and placed it under webapps. Then I started the server, it worked.
Later I made few changes in the code and created WAR file and deployed the same in webapps folder. But it is not taking the latest changes.
I did in the following way
1. Stopped tomcat instance by shutdown.bat
2. Placed the new WAR file in webapps.
3. Started the tomcat instance by startup.bat
Still no changes are reflecting? What could be the reason?
Manual deploy:
To deploy or redeploy a war file is simply dropping your war file into the $CATALINA_HOME/webapps directory of a Tomcat instance. If the server is running, the deployment will start instantly as Tomcat unpacks the archive.
If Tomcat is not running, then the server will deploy the project the next time it is started.
Sometimes you need to stop Tomcat and delete everything from $CATALINA_HOME/temp, $CATALINA_HOME/logs directories and delete the war and the related unpacked folder from $CATALINA_HOME/webapps directory. After that just copy your war to the right place and start Tomcat.
If the deployment is finished without error then you can see the following message in the tomcat log:
OK - Deployed application at context path /myapp
Otherwise an error message will appear which describes what was the error.
We need to see the Tomcat logfile if you need more help.
you should clear the log and temp files of tomcat
Try checking the autoDeploy flag in server.xml. Below is the description for this flag.
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
autoDeploy
This flag value indicates if Tomcat should check periodically for new or updated web applications while Tomcat is running. If true, Tomcat periodically checks the appBase and xmlBase directories and deploys any new web applications or context XML descriptors found. Updated web applications or context XML descriptors will trigger a reload of the web application. The flag's value defaults to true.
1)Please check your war file size. Then update it in the =apache-tomcat-9.0.53\webapps\manager\WEB-INF\web.xml file.
2)Remove dependency "javax.validation" from POM file
3)Add dependency org.glassfish.web
4)Check your log files. and modify dependencies accordingly.
Related
I want to deploy from my Jenkins to Tomcat without using this "Deploy to container" plugin .
So I am thinking of a Tomcat REST API to deploy a war file. The Tomcat and the Jenkins are on different servers.
Maybe it is enough to just copy the file to the webapps folder ? But then I still have to deploy it meaning to start it . Right ?
Honestly I have not found any REST API to deploy to Tomcat so far. The problem is to make the .war file available .
From Jenkins, you can use a bash script to transfer the .war file to your Tomcat webapps directory (the code is the same if you work with a pipeline).
First, stop the Tomcat
ssh tomcat#tomcat '${TOMCAT_BIN_PATH}shutdown.sh'
Then, copy the war to the webapps directory of your Tomcat
scp -r -p jenkins#jenkins:path/to/war/file.war tomcat#tomcat:path/to/webapp/
After that, you have to start the Tomcat and the .war will be deployed automatically
ssh tomcat#tomcat '${TOMCAT_BIN_PATH}startup.sh'
If you are using Maven, I suggest you to take a look at tomcat-maven-plugin, you can find it here. You can deploy the war file with the following command:
mvn -B -P deploy-profile-from-pom-xml tomcat7:deploy-only
An example of implementation can be found here
UPDATE
If you want Tomcat to delay the webapps directory checking, you can add backgroundProcessorDelay to your server.xml configuration
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" backgroundProcessorDelay="15">
Tomcat will only check for a new .war every 15 seconds with this code for instance.
I have a peculiar problem with deploying a spring boot web application with Tomcat . I deploy a spring boot webapplication into tomcat 8.5.8 . The deployment steps follows as below via a pascal script in windows system:
1) Tomcat is stopped
2) A sleep time of 10 seconds is given
3) Then the deployed directory is removed
4) The war file is removed
5) Then the new war file is placed
Sometimes, in webapps directory , the old deployment folders seem to present partially [i.e. the step 3 fails]. Due to that the new war file is not getting exploded. The old deployment directories are also empty within.
I am setting antiresourcelocking to true in my war file . The i use deltree command of pascal to remove my directory
Note that if you delete the war file without stopping the Tomcat it will delete the corresponding directory in a short time. Also it's worth taking a look at existing tools that can be used to streamline the deployments stack overflow post on deployment
I am facing a problem by deploying a War file on a Tomcat Server.
My Tomcat Server configuration as follows:
My steps to deploy:
I created a WAR file in Eclipse Kepler (Windows 7 64 bit, no Maven used).
Uploaded it with a Tomcat Web Application Manager.
Clicked deploy.
Tomcat unpacks WAR file in tomcat/webapps and throws me NullPointerException. It is missing some files that should be imported to project to work it right.
When I was working in Eclipse, as a source for these files I gave a workspace path, given in the Server settings and adding the wtpwebapps folder, which was offered by Eclipse by default. So my complete path looks like this:
C:\Users\myUserName\kepler\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myProjectName\WEB-INF\classes\project\fdsProject\FDS.prj
Now, when I deploy the project, it locates in a webapps folder, not in wtpwebapps and if I try to start in a browser, it shows me NullPointerException. But as soon as I copy the wtpwebapps folder from my workspace to the tomcat installation folder, near webapps, my project is starting successfully.
It means that I cannot start my project on another server, just deploying a standalone WAR file. I must add manually the wtpwebapps with my project in into the tomcat server installation folder. How can I optimize it and start project just with a WAR file deployed?
Thank you!
EDIT
My project structure is looking like this:
Stop the Tomcat Server
In the settings view Tomcat Server settings in Eclipse -> Server
Locations, check Use Tomcat Installation(...)
Now, you can change the Deploy Path, if you want webapps, then input it.
EDIT
The values below control how tomcat deal with war file
autoDeploy="true"
unpackWARs="true"
Just search these values in your server.xml file and edit values as you need.
If you want to be able to deploy your app as a WAR file, you need to refer to everything within it relative to the app itself, not with absolute file paths, not even as file paths if you can. If you have code that requires a java.io.File, rewrite it. The point is that you don't care where things are, you just care about how to get to their contents. For a Servlet, you can read anything on the web app's classpath by calling getResourceAsStream() on the correct class or classloader.
See getResourceAsStream() vs FileInputStream .
I have created a Job in Jenkins where in I have added a "Post-build" action using "Deploy war/ear to a container" to deploy WAR to a running Tomcat. The job is working fine.
The job fails when there is error in deployment on tomcat due to some reasons (like unknown JNDI in context.xml).
I want to know if there is any way to rollback the deployment to the previous build that was in tomcat in case deployment from my Job fails.
In tomcat, you can just deploy a war file with a different name, for example a different major version. So, inside your webapps folder, you have two war files:
process-1.war
process-2.war
... and corresponding directories (at least, if you've set unpackWARs="true" autoDeploy="true" in server.xml):
process-1
process-2
Both versions are usable at this point. The standard application url will default to process_2.
If you remove process_2 war file and directory, or - equivalently - press "undeploy" in the tomcat admin console, the old version will be default again, which means you've rolled back to the older version.
when I run my dynamic web project from eclipse it gets deployed to wtpwebapps. However I want to deploy a war file to tomcat so when I checked here in SO this came up
How to deploy a war file in Tomcat 7
It says I have to deploy to webapps folder in tomcat.
Can anybody please explain me the details between wtpwebapps folder and webapps folder in tomcat and also if I can deploy war files to wtwebpapps folder instead of webapps folder.
wtpwebapps is an eclipse-specific folder created when you run a dynamic web project on Tomcat within eclipse.
Webapps directory is within the Tomcat home and it's where you copy over your WAR files manually.
Recently, i've struggled with webapp strange behavior while debugging in Eclipse. I've noticed that it was double deployed.
My setup was:
web module with context path that differs from document base;
enabled autoDeploy in server.xml;
and deploy was set into webapps directory.
When checking tomcat-manager i've noticed that this webapp was deployed once with its context path name and once with document base name.
Here is what the documentation states (All credits goes to octopus, Tomcat docs):
If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
And, i believe it's the main reason to use wtpwebapps instead of webapps for Tomcat with Eclipse.