difference between wtpwebapps and webapps folder in tomcat - java

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.

Related

Server tomcat not deploying latest WAR changes

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.

WAR file can't be deployed on Tomcat 7 without wtpwebapps folder

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 .

tomcat is not autodeploying my .war file

i hope this is no duplicate. I allready searched for an answer, but did not find anything that fits.
I have a .war file called "app.war" and put it into the webapps folder of my tomcat. When i start tomcat, the .war file should actually be deployed, but it does not.
In my server.xml unpackWARs and autoDeploy is set to true. The tomcat service in the system is installed.
Does the content of the war file needs to have a special structure? I have the following structure:
I create the .war file with gradle by using "gradle build". My project structure is a typical maven java webapp structure.
Is there maybe anything missing in the war file? I have no more idea why the war file is not being deployed. What is also strange to me, is that when i unzip the war file in the webapps folder and restart my tomcat, the app won't be found by the tomcat.
Did you checked the permission of the war file and the webapps folder? Commonly tomcat is started by a user different to root , so , If you copied the file as root, the tomcat process never can access it .

Deploying a Dynamic Web Project with Tomcat

I currently have a working servlet created in Eclipse. When running it from the Tomcat plugin, everything works, and my app shows up at localhost:8080/project_name/. However, when I package the project into a .war file and place it in the /webapps directory of Tomcat and start the server, the servlet cannot be accessed. In Terminal, I can see Tomcat loading my project, and a temporary folder of the unarchived project is also created in /webapps. However, I simply cannot access my servlet.
Note:
I'm using Tomcat 7 and I don't have a web.xml file in my project.
How are you creating the war file? Check if your war files contain jar files under WEB-INF/lib folder and if the class files are not missing. You can easily verify it under tomcat/webapps/[project name] folder.

how to deploy a eclipse dynamic web page in tomcat?

I developed dynamic web page in eclipse.I also configured apache tomcat in eclipse juno.In eclipse it run on server fine.I don't know how to deploy the dynamic web page in other system tomcat server.My folder structure.
Tomcat 7.0
-webapps
-Myproject-Folder
-WEB-INF
-classes
-lib
-web.xml
create a folder in your tomcat webapps folder
Then create another folder WEB-INF and index.html
Then in WEB-INF folder create three other folders classes,src,lib and web.xml
In classes folder keep all the .class files.
If you want to keep the source files then these should be placed in the src folder.
In the lib folder keep all the necessary jar files like activation.jar,mail.jar(if you are using java mail Api).
Now map correctly in web.xml
Now if your web.xml is correctly mapped then open a browser and type
http://localhost:8080/your_folder_name
8080 is the default port number.
just copy the "Myproject-Folder" to the "webapps" folder of any tomcat
Depending on how you want to deploy it, you can just copy the folder under "webapps" of your current Tomcat or package it into .war and put that under webapps folder of the target Tomcat.

Categories