How relative paths to .war work? - java

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.

Related

How to put JAR files in the /WEB-INF/lib/ folder before exporting the program into a .war file and deploying it in TomCat?

Just what the question says. I am using Eclipse. I can't copy and paste JAR files into the /lib folder that I make.
The TomCat Developer Guide says to put JAR files into this folder for the app to work:
/WEB-INF/lib/ - This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.
Details:
I am using DigitalOcean to deploy an application through TomCat.
I get the Home Page up, but when I click to another link on the home page, I get this 500 error:
Message The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.JasperException: The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application
How do I solve this please?

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.

How to read configuration file in EAR from the jar with in it

I have a configuration file in my jar file, I was reading it with this.getClass().getResourceAsStream() method using relative path. But when I was trying to use weblogic deployment plan to modify the configuration file when deploying it. It seems there is no way to find this file if it is in the jar.
Now I took it out from the jar and put this file inside the META-INF folder of the EAR file so that weblogic deployment plan can read it. But my problem is, I don't know how can I still read this file from my java code of this jar file. Is there any way to read the file in EAR from the jar? Thanks.

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