WAR file with symlinks - java

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?

Related

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.

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?

Command line - call class from jar which is in war

I have a .war file. Inside this .war file I have WEB-INF folder. Inside WEB-INF I have a lib folder and inside this lib folder I have a .jar file. Inside this jar I have a class with main method. I need to call this method. Can I do this from command line? I don't have an option of deplying war file, so I need a command which will access my class with main method through the war file.
Easiest way to do this is to go to the location where your jar file is located from command prompt and type java youpackagename.yourclassname .for eg java net.grinder.Grinder
Accessing the jar in the war package might be difficult. Due to the fact that war packaging is intended for deployment on a Java Web server, the war packaging is obsolete and not handy for you usecase. Unzip the war archive and run the contained jar archive after unpacking like you'd run any other jar archive with java -jar /path/to/archive.jar (you'll find a ton of examples on this page).

Missing files when compiled to WAR

I have quite an interesting issue. I'm running maven to compile my Servlet site into a single WAR File. This works completely fine on my local machine; and even when I change my deployment settings to use just the war file, it works fine. However, when I deploy the WAR file to the server, I'm getting 404 errors. I'm no expert with WAR files, so is there some sort of internal file that specifies the location of resources that I need to look at?
First try to unzip your war (wars, jars, ears are zip files) and see if your files are actually there, verify if your unzipped war contains:
dir WEB-INF
file WEB-INF/web.xml
dir WEB-INF/lib with the jars your aplication depends on
dir WEB-INF/classes with *.class files, where your servlets and related classes are supposed to be (if you have decided to have them there and not in a jar in WEB-INF/lib)
static resources in the root directory
You could make your conclusions of what is missing in your war.
You could also try to build your own war manually (creating a zip file with the structure I mentioned above and renaming it as *.war) if you have problems with doing it by your IDE's options

Problem updating existing webapp in Tomcat 6.0.20

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.

Categories

Resources