I have a WAR file called ROOT.war where I uploaded into Tomcat few days back. There I have few "public" HTML pages like index.html, about.html etc. These pages has no connection with the programatic part of the application, instead containing a link for login.jsp.
Now, I need to change the content of the index.html and about.html. What I was used to do is rebuild the entire WAR file and re-uplaod it, but now can't do it for small and iterative changes like this because the application is in use.
So, can I simply access the webapps -> ROOT folder in Tomcat and replace the index.html? Will it affect the process of the application?
It works but avoid such practices which lead to discrepancies.
Follow standard deployment process - rebuild the entire WAR file and re-upload it during deployment window.
You can, and It will work. You can even change the JSP code. The only issue you may have is that when you redeploy a new version of the war, changes made in the server will ve overriden by the new version, so you better change it in the original tool also.
Related
This is a pretty strage and hassle problem i have here.
I created a Dynamic Web Project in Eclipse and created an HTML file named "inicio.html".
I put this into my web.xml <welcome-file> and all seemed to work okay.
I could Run on server without any problem.
Until i dragged a folder into my webapp.
folder in my project
Now when i run on server my file doesnt change at all, and even when i change the welcome-file from web.xml it doesn't change.
It looks like there's another file somewhere like a copy from the original "inicio.html" that's executing on my server.
this is an example of what's happening
I tried to change my TomCat's web.xml file and it doesn't works.
It's unlikely that the new IMG folder is relevant. Deployment Descriptors aren't really hot swappable.
Make sure automatic building is enabled on the Project menu, and then try right-clicking on the server in the Servers View and choosing "Clean Tomcat Work Directory". Otherwise, you'll need to restart the server for changes to take effect.
I have an application represented by an exploded .war:
/webapps/myWebapp
Usually, when the .war is present, I do the following via command line:
touch /webapps/myWebapp.war
This changes the last modification date on the war, making the tomcat redeploy the application inside of its folder: the old folder is deleted and a new one is created again.
Unfortunately I don't have the .war, but only the application folder and, sometimes, I need to change some files inside of it and a restart is requested in order for the changes to take effect.
Is there a similar way to accomplish the same without restarting the whole tomcat server?
Alternatively I could do that via the manager console...the problem is that I want my user to be able to only restart that application, not every single application deployed.
Can you give me some hints/suggestions? Thanks
You may want to look at the property WatchedResource
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
WatchedResource - The auto deployer will monitor the specified static resource of the web application for updates, and will reload the web application if is is updated. The content of this element must be a string.
Just add paths of the files that you want to see the changes.
I'm using Wildfly 9.0.0.Alpha1 with Spring STS 3.6.3 and JBoss Tools, i don't find the way for update my changes to static content inside my server without the need of use incremental deploy (I enabled exploded deployment in the wildfly server), so when i do a little change to my resources, I have to refresh the project in eclipse STS so then it makes an incremental deployment, this takes about 15 - 30 seconds which is annoying and a waste of time
There is a way for update a static content in a exploded war without incremental deploy?
You can edit your subsystem entry for undertow, adding a location and file for a path within standalone/tmp. And then you can add symbolic links to that path at runtime every time you want to share additional static content. You can use Files.createSymbolicLink(...) in Java. Just be careful that the attributes of your symbolic links let them be deleted without deleting the targets. Also, make a start script that recreates your subdirectory in tmp as needed before wildly starts. If you have an undertow location that points to a folder that doesn't exist, the location (context, like /static) will not be created. Once created, undertow will serve up any subfolder or file you add to it once location is created at startup. Make sure you add directory-browsing="false" attribute to the file element for the folder if you don't want people to be able to list contents of folder.
OK, so I found out so far, that despite me having the jquery.js file in the same folder as the jsp file I have, the Ecipse-Tomcat configuration is executing the files in a different location and it takes all the files except for jquery.js How is this possible and how I can make it automatically load the file in it execution folder?
In my case jquery refuses to work unless I specifically put it in the folder where tomcat is executing the files... Any ideas? Thanks.
Alright, after a few hours of struggling, I finally found a solution to this problem. Seems Eclipse Tomcat probably isn't refreshing and checking the files in the path well if you're using any other perspective than Java EE. In my case I was using and working all the time in the normal Java perspective and this way it never reloaded even when I would click refresh. Now however I switched to Java EE view and clicked refresh. The file finally appeared and jquery finally started working!
All JS/CSS/HTML files are static resources and would be served from Tomcat through DefaultServlet. You would need to configure the default servlet in your web.xml with appropriate location to the folder where these are present. This has nothing to do with the location of JSP, though the JSPs can also go under the same folder.
I have created a dynamic web project, and use Apache Tomcat as a server.
In my servlet I'm creating a text file and want to reuse that in a JSP. However they are by default created in the installation folder of Eclipse when I do something as simple as the following:
File f = new file("test.txt").
I don't know why this happens. Is there a way to create the file in the WebContent directory as I want to make that file available for download in my JSP.
Java has a concept of the "current directory". When you start an application via Eclipse, this may indeed point to your installation directory. If you don't specify any path, a file will be created in this current directory. Hence the reason why your test.txt ends up there.
The WebContent directory is a something that is specific to Eclipse. Your code should not depend on putting anything there. You only start your application via Eclipse when you're developing it, not when you're deploying it to a live server.
The content of this directory will become the root of your .war, which is a well known location independent of how you start & deploy you app, BUT you still cannot depend on writing anything to this location at run-time. You might deploy your application as a packaged .war (likely for live deployments) or you may deploy your application unpackaged but then your application server may simply not pick up any changes done at run-time.
What you can do if you are sure your application only runs on a single server is writing the files to a well known location on your file system, such as /tmp, or /var/yourapp/files, etc. The code serving up those files can then pick them up from that location.
If you want to play it 100% safe according to the Java EE rules, you'd store your files on something like an FTP server that has a configurable address. Technically your war could be shipped between nodes on a cluster and requests could end up going to different machines, so depending on a local filesystem wouldn't work then.
Executing this statement this.getServletContext().getRealPath (""), you'll obtain the path where Tomcat WebServer is pointing at at runtime. You could add a folder "MyFolder" and call this statement:
new File(this.getServletContext().getRealPath ("") + "/MyFolder/test.txt");
Anyway, the default path looks something like:
...\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\<NameOfYourProject>
Note that when you create a new file, it won't appear in your immediate workspace (check the .metadata path), unless you change the runtime location tomcat should point at.