Access folder outside WAR in Websphere - java

I have a requirement where I need to download a file from folder placed outside the project folder, so that we dont have to build EAR and deploy each time we need to change the file.
I am using WAS 7 and Maven for build.
If I specify direct path its able to download without any concern,But I need to deploy the EAR in QA env so I need to use relative path irrespective of env.

I did as Sampada posted in comments.
Added the FILE_PATH in properties file which is placed outside the EAR.

Related

How to find .properties file in maven based java web application?

Recently I have developed Java based web application and used maven for making a build.
As per standard convention, I have added all the .properties file in folder "src/main/resources". After deployment of .war in tomcat, I wanted to edit properties file without making new build. Is it possible to edit the properties ? If Yes, In which folder I can find the properties file ? (I could not find the properties file in the server /tomcat folders)
If this is a web application, inside the war,you should be able to find the contents of src/main/resources in below location:
war -> WEB-INF -> classes folder.
You can edit the properties file there, restart and it should work.
Just got to the folder where your war is located somewhere in your system.
Target > War > Web-Inf > Classes.
Make changes and redeploy.

Update xml file in JAR with weblogic deployment plan

I have a java application(not a EJB, not a MDB, it has a class implements ApplicationLifecycleListener). I build this java application into a jar file then create an EAR file include this jar, deploy the EAR file on a weblogic server, it works perfectly fine.
Now I want to use weblogic deployment plan to update some of the values in a configuration file which located inside the jar file. I generated the deployment plan, but it does not recognize my configuration XML file. I tried manually add it to the deployment plan, and use the deployment plan to redeploy this application. But nothing is updated.
I have read some examples of updating ejbs, but did not find anything about update a JAR's configuration inside an EAR, can anyone please give me example or send leave a link on how to properly use weblogic deployment plan to update a configuration file inside a JAR which is packed within an EAR file. Thanks.
You probably have to place the XML file in a jar file with same name under the same path as the original and use this jar in AppFileOverrides.

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?

Where do I place the applicationContext.xml file within Spring project directory

I am trying to learn about the Spring framework for Java and I am not sure where about's I am supposed to put the applicationContext.xml file for configuring the spring beans. My directory structure is as follows:
Do I put in .settings? Or should it be put at the top level within springapp?
Thanks for the help.
Put into directory WebContent/WEB-INF.
Resources placed into WEB-INF folder are not accessible from web, they are application internal resources. This is good, because your applicationContext.xml shouldn't be accessible from web.
Other good options are WebContent/WEB-INF/classes or just src (both are equal).
Files and folders with . contains Eclipse configuration files, they are internal for Eclipse - do not use them.
I recommend to put it in the src (or src/META-INF) folder and access it via classpath:applicationContext.xml (or classpath:META-INF/applicationContext.xml). (Eclipse will copy this file to WebContent/WEB-INF/classes when it build the war archive.)
Because:
The mayor advantage of src over src/main/webapp/WEB-INF / WebContent-WEB-INF is, that you can access the src files even in the tests (via classpath:applicationContext.xml)
Do NOT put it .settings because the content of this directory gets not deployed in the Web App (it is eclipse configuration folder)
Of course when you use maven, then put the file in src\main\resources (or src\main\resources\META-INF), Maven will copy them to the classpath folder while compiling.
WEB-INF or its subdirectories. This folder's content is packed directly into the root war file, so files that are directly under this folder are accessible as resources with path like '/foo.xml' (or in spring notation classpath:/foo.xml
It needs to be in the classpath. You can put the original editable instance anywhere (e.g. a config directory off the root) but then you will need to have your build management tool (e.g. Ant or Maven) copy it into the classpath for the runtime.

Eclipse : Add jar file and not depend on local machine path

I'm working on Eclipse with a java project. In this project, I include a jar file. But when I include it, eclipse remembers its path base on local machine. For example : if I'm on Windows, the path will be C:\Document\... and if on Linux, will be /hqt/workspace.. for example.
Although, in project folder, I create a folder lib and copy jar file to here, hard link to this jar doesn't change. So, when I copy this project to another place that jar file doesn't same with my current local machine, jar file will be missed and must re-config again.
So, my question is : How can i include jar file and not depend on local machine path.
Thanks :)
Do not use "Add external JARs...". Put the jar in the "lib" forlder you have created in your project then add it to the classpath using "Add JARs...".

Categories

Resources