Problem updating existing webapp in Tomcat 6.0.20 - java

In Tomcat 5, I would build a WAR file and place it on my test server. On this server there was a my-app.xml file in the CATALINA_HOME/conf/[EngineName]/[HostName] directory that pointed to my test database. Once I finished testing, I would send the WAR file to my clients IT department and they would put the file in the CATALINA_HOME/webapps directory. On their instance of Tomcat, they had a different my-app.xml file that pointed to the production database.
Recently we upgraded to Tomcat 6, when either of us copy the WAR file into the webapps directory, it deletes the my-app.xml file. After it is deleted, if I copy a backup of my-app.xml file into the CATALINA_HOME/conf/[EngineName]/[HostName] directory, Tomcat ignores it, even if I reload the webapp from Tomcat Manager.
I tried adding a context.xml file to the META-INF directory in the WAR file. When Tomcat was expanding the WAR file, it would overwrite the my-app.xml file with the context.xml file. If I then copied the backup of my-app.xml file back into the CATALINA_HOME/conf/[EngineName]/[HostName] directory, Tomcat deletes the WAR file and the expanded directory.
I can include the appropriate my-app.xml file inside the WAR file, but this means building two WAR files, one with the test my-app.xml and one with the production my-app.xml. I also can get it to work if I copy the WAR files or the my-app.xml backup files in a specific order into the correct directories. I am not fond of either of these solution for multiple reasons.
What am I doing wrong? Why does this not work in the new version? Do I need to change an option? Do I need to change my process? (NOTE: The client's IT department does not want to have to stop and start Tomcat to redeploy a new WAR file.)
Thanks!

It sounds like Tomcat's auto-deploy is interfering with your manual deployment. Try either deploying your WAR file to another directory (i.e. not the webapps dir) or turning of autoDeploy in your server.xml. There's some more notes here: http://tomcat.apache.org/tomcat-6.0-doc/config/host.html#Automatic%20Application%20Deployment.

Related

how can I deploy a WAR file to Wildfly?

In relation to deploying a WAR file to Wildfly, where should the file be copied to?
I don't see where the file is:
thufir#dur:~/java/wildfly$
thufir#dur:~/java/wildfly$ tree wildfly-17.0.0.Beta1 | grep wildflyMaps.war
│ └── wildflyMaps.war
thufir#dur:~/java/wildfly$
seems to be exploded for deployment:
Re: Can't see the .war after deploy ehugonnet Apprentice ehugonnet 21-Aug-2017 2:47 AM (in response to Claudio Miranda)
During runtime the enabled war files are exploded by vfs in the tmp
directory. Those files will be deleted on stop / restart / disable.
The reference content is in the content data directory for recreating
the tmp files.
Standalone mode
The standard location for deployments in standalone mode is Wildfly_Home/standalone/deployments so you can copy your war to that folder via Java or any other means. It will deploy then upon starting the server. And actually it will auto-deploy even while Wildfly is running (and if not, just create a file and call it wildflyMaps.war.dodeploy).
Domain mode
With this, you can't just copy a war file to a directory. It can be done via the cli, but easier is to log on to the management console and go to the deployments section.
Once deployed, if you open up the domain.xml, you'll see something like this:
deployments
  deployment name="wildflyMaps.war" runtime-name="wildflyMaps.war"
   content sha1="d991471f79045413a7c63b8c2b5d4dc345be8808"/
  /deployment
/deployments
And using the above example, you'll find the deployed file at:
Wildfly_Home/data/content/d9/91471f79045413a7c63b8c2b5d4dc345be8808
and in there has a file called content. Copy that elsewhere and rename it as anything.war and you can open it and see that it is the war that you deployed.

How relative paths to .war work?

I have a Spring Boot app that I tried deploying to a .war to run it from a Tomcat server.
Before this I was deploying to a executable .jar and everything worked perfectly.
In the app I need to read a .json file and also read a directory, their locations are given as relative. When deploying to .jar I would have the file in the same folder as the .jar. I would access it as: ./branchMap.json. The directory would also be in the same folder as the jar and I would access it as: ./patches.
Now when I am deploying to .war I place the app in webapps in Tomcat and I place the json file and the folder also in webapps. When I run the app it is able to read the json file, but it is not able to read the /patches folder.
Why is this happening? I have seen that Tomcat tries to load the /patches folder as a app, in is listed in the tomcat manager. How does this interfere with the app trying to read access that folder? Is there something different in the way that a app deployed to war accesses relative paths?
Read the paches folder location from properties file and in the property file you can mention the full path of the patches folder.

The best way for a WAR file to receive data from an external file

I have a WAR file that requires additional data from an external config file residing in the same folder as the WAR file.
But once I deploy them to Tomcat, the WAR file and the config file will be residing in different places right?
Do I need to insert a special file path to my project before building the WAR file to make sure that the WAR file will still find the config file after deployment?
Thanks.
You can:
include the config file inside the war and read it from this predefined location. This isn't good if you're going to change it after you deploy since every time you deploy a new war, your changes will be overwritten
put the config file outside the war (and maybe even outside of tomcat) and read it from there. Doing this, your changes will survive redeploys of the war.

Change context-root inside WAR file

I am really new to WebLogic deployments. I have the below situation:
I have a war file which is already deployed on WebLogic 8.1, I want to pick the same war and deploy it on the same server without bringing the original site down. This would definitely give me a exception saying the context path already exists. I have no way of recreating the war file, hence I will somehow have to modify the war file to change the context root. Is this possible?
And if it is possible could you also confirm that both using the same data-source(JNDI) would not cause any issues to the existing site.
Thanks,
Sahana
Yes you can deploy the same war file multiple times and yes you can change the context root. You will want to do something like the following if you cannot rebuild the war file yourself.
Unzip the war file (jar xvf myfile.war)
This isn't entirely necessary but it will help you understand the structure of the war file. Zip tools can modify a file in place. Try 7zip or use the Windows zip utility via right-click Open
Edit the weblogic.xml file with the new root <context-root>/new-root</context-root>
Rezip the war file (jar cvf mywar.war folder_it_is_in)
Here are other examples that may help as well:
How to deploy EAR application twice on WebLogic server?
How to deploy the same web application twice on WebLogic 11g?
How can I use Weblogic (12 C) without the application context in the URL?

WAR file with symlinks

I have WAR file that contains symlinks for certain libraries.
When I extract the war file into webapps folder using unzip command it creates the symlink properly and web app loads without any issues.
However when I place the WAR file in webapps and let Tomcat deploy it , the symlink becomes a simple text file.
How do I overcome this situation, is there a way to customize the WAR explosion process.
EDIT
I suspect this is because Tomcat user Jar command to unpack a war file, is there a way to make tomcat use unzip command instead?

Categories

Resources