I have a maven project ,say hello.In my /var/lib/tomcat8/webapps folder,i have placed its .war file,as hello.war.
Now I made some changes to a js file,run mvn package and copied the target/hello.war to tomcat8/webapps folder.
The server still serves old JS file.
Things I have tried:
1.Tried opening in private window.
2. Removing Catalina folder in tomcat8/work folder.
3. added to context.xml
But none of them work.Also deleted old hello.war in webapps and copied again,but still problem persists.
However,when i tried copying it as hello1.war in webapps folder,the servers serves the new file.
Can someone guide me how to solve the problem?
Clean and rebuild your project war file.
Delete the hello folder from server. Then restart the server.
Sometime .js is loaded from cache, try Ctrl + F5
Tomcat isn't responsible for this. Some intermediate Web cache is doing it, or your browsser itself is caching.
Try to undeploy the app from http://localhost:8080 , in tomcat manager, then make shutdown from tomcat/bin and finally copy the war to your webapp folder and startup tomcat again
Unzip the war at some temp location and check if the unzipped JS file is the one which you are expecting. If it is, clean the tomcat webapps directory by removing the previous version war and the unizpped directories and files from that war. After that, copy the new war into your webapps folder and start the server.
One other thing, if you are using eclipse and using external maven build then after re-building your project refresh that project in your workspace and then copy the war file.
The ideal thing to do and which I normally follow is :
Delete temp folder
Delete work folder
Delete webapps/hello.war file.
Delete webapps/hello folder
In my case one file was stale and served old content whatever changes I did, the other one used on the same jsp page was successfully refreshed.
Restart/Publish/Clean Tomcat work directory... in eclipse didn't help.
The only thing which did the trick was cleaning the cache in Firefox.
I still have no clue why first file was saved in cache, and the other - not.
Related
Question 1: May I ask what is the difference between deploying a java webapp with it's WAR file vs just copy/pasting the build folder into tomcat webapp folder?
Question 2: Somehow I am told to deploy my project just by renaming my /build/web folder to /build/, then copy and paste this folder into tomcat/webapp folder. Tomcat did serve the web app and I could access it via url. But the problem is that I suspect my System variables were not set. I start up a servlet and put this code in this init(ServletConfig config) method:
System.setProperty("LogPath","D:/Test/logs");
And doing this in my log4j.properties
log4j.appender.file.FILE=${LogPath}/wrapper.log
wrapper.log is not found in the designated directory but a stdout.log is found in tomcat/logs folder.
I am sure the init() method was fired because I have a quartz scheduler there. I am suspecting that my System.setProperty was not set. Any hint?
Update: With all the same source code, I have no problem if I am deploying with a WAR file. The ${LogPath} in log4j.properties work as expected.
Let me answer you the first question.
WAR file is a zip archive with different name. When you deploy this file to the Tomcat server, it unpacks this file to its folder as you would do it by copy-paste. If you are just developing your own project in your own environment and you don't want to distribute it, you don't need to create a war file. But if you want to distribute this project, I recommend you to create a war file. One file is easier to be sent.
Read more on Wikipedia http://en.wikipedia.org/wiki/WAR_%28file_format%29
I am using Spring framework MultipartFile to upload files using my application to the server, though whenever I do any 'Project > Clean' from Eclipse STS, all files I've uploaded earlier get deleted automatically.
I am saving all files uploaded to the following path:
String rootPath = request.getSession().getServletContext().getRealPath("contentrepository");
Which in real path get translated to:
C:\springsource\apache-tomcat-7.0.40\webapps\myapp\contentrepository\
so can someone please tell me what I am doing wrong here to cause those files to get deleted each time I do a Porject > Clean? Is it that STS clean command empty the webapps folder content? Shall I change the upload files folder location to another locations outside the apache folder totally?
Thanks or your time
Spring Multipart upload has nothing to do with your problem!
Whenever you clean your project, all deployed directories will be cleaned. Similarly, when you deploy your project, complied files will be deployed to server.
When you upload a file, it is save in your deployed location, however on cleaning all the data is lost.
If you want to persist file during your testing i.e want to have files even if you clean your project:
- Store uploaded file to some other location.
OR - Take backup of uploaded files before you clean your project and copy them to deployed folder.
You might like to view this question, for what exactly 'clean' does.
I have an application/war deployed in server. Now at runtime I want to add an xml document to the war/application. can I do that? if yes, what is the path of an war/application for it to be added.
You have to repackage the WAR, redeploy, and bounce the server. It's not that simple.
You can make that data available without the hassle if you put it in a database and have your application access it there.
in the webapps/WEB-INF folder you can find the xml files
It depends on the servlet container/application server.
If you are using Tomcat, wars are getting unpacked to the webapps directory inside the Tomcat directory.
Move webapps/app directory outside the webapps directory, what will cause an undeploy of app
Put your xml file into the app directory
Move app back to webapps what will cause a deploy
I have a web application deployed on tomcat 7. Its context file, named myAppName.xml is located in
$CATALINA_HOME/conf/Catalina/localhost folder.
The problem I'm facing is that on each overwrite or undeploy, my configuration file is deleted from $CATALINA_HOME/conf/Catalina/localhost folder and I have to copy/paste it from a backup location.
How can I prevent this behavior? I don't want to copy/paste context file everytime I change something in webapp.
Put it into web/META-INF in the source tree, then Tomcat will copy it out of there into conf/.... on each deploy. Tomcat 7 won't even do that by default, just use it where it is.
I am right now working with JSP and using tomcat Apache for that.what my problem is when i am creating one single JSP page and putting in root directory of tomcat then its working fine.but now i have one project that contains some useful jars and other java classes so how to put that whole project directory in tomcat.
I had put that in web app directory but its giving me error as follows
The requested resource (/dailymotion-cloudkey-java-73f6f35/examples/upload.jsp) is not available.
I am Giving snapshot of my web app folder where i had put this folder name as dailymotion-cloudkey-java-73f6f35
i know that i am doing mistake while putting dailymotion-cloudkey-java-73f6f35 directory in tomcat.
but i am totally new in this so i couldn't find out so can anyone tell me
tree Structure of my project
I think dailymotion-cloudkey-java-73f6f35, does not have WEB-INF folder with web.xml file. Due to which it is not able to locate the resources.
or
You can copy your dailymotion-cloudkey-java-73f6f35 project directory into ROOT folder and then try the same URL.
Put it anywhere, but put a context file for your webapp to TOMCAT_HOME/conf/Catalina/localhost which points to for webapps's directory with the docbase attribute. Read details here.