How can I override server.xml or context.xml file of tomcat 8 from project? Because I am using data source in server.xml.
You cannot override the server.xml from your project. On the other hand you can override context.xml. You can do so by (c/p from docs)
In an individual file at /META-INF/context.xml inside the application
files. Optionally (based on the Host's copyXML attribute) this may be
copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to
application's base file name plus a ".xml" extension.
As described, to override context.xml you should add a META-INF to your webapp's root and place inside your context.xml. Note that in order for your projects context.xml to take effect, there should not be already set context.xml for that particular project inside tomcat instance
In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The context
path and version will be derived from the base name of the file (the
file name less the .xml extension). This file will always take
precedence over any context.xml file packaged in the web application's
META-INF directory.
Related
I am running on WebSphere Liberty 17.0.0.4. Deployed a web application and custom authentication module which is located under {wlp_install_dir}/lib directory. And that jar file is marked as library in server.xml file. Here is how it looks in server.xml
<library id="CustomLoginModuleLib">
<fileset dir="${wlp.lib.dir}" includes="custom_auth.jar"/>
</library>
Now the thing is, I want to use .properties file located inside custom_auth.jar file to the web application.
Have tried following code snippet to access:
this.getClass().getResourceAsStream("location/of/package/file.properties");
ClassLoader.getSystemResourceAsStream("location/of/package/file.properties");
But, neither works.
Any idea how can we access properties file located in library jar file.
Please see my response to this same question on dwAnswers at:
https://developer.ibm.com/answers/questions/444708/how-to-access-properties-file-located-in-library-j.html
To summarize the answer from there:
(1) I would never recommend putting user-provided JAR files in the {wlp_install_dir}/lib directory - that dir is only intended for IBM-provided JAR files. Instead, I would suggest putting your custom_auth.jar in your server directory or in a shared directory.
(2) You will need to associate the shared library with your application(s) like so:
<application location ="{appName}.war"> <!-- or {appName}.ear -->
<classloader commonLibraryRef="CustomLoginModuleLib" />
</application>
Depending on your needs, you can use a commonLibraryRef (as shown) or a privateLibraryRef. More info on shared libraries can be found here: https://www.ibm.com/support/knowledgecenter/SSD28V_9.0.0/com.ibm.websphere.wlp.core.doc/ae/cwlp_sharedlibrary.html
(3) As for loading the file in the Java code, your first line will work - assuming that this refers to an instance of a class in your application. I also assumes that the path you pass to the getResourceAsStream method is the same as the path to the file inside the library JAR.
Hope this helps, Andy
I want to set my relative file path in a properties file so my SaxReader can pick it up when it runs on Tomcat server. I know this should be easy but I've forgotten forgive me :)
I know Spring Boot has application.properties file but I don't see a way to hook in here.
Is there a way to set the relative path in a properties file that will get picked up by Spring Boot and the SaxReader will see it?
As it is I'm hard coding just the filename and putting the file in the resources folder that serves up the templates and static content such as css and js files. The filePath system.out gives: org.dom4j.DocumentException C:sts-bundle\sts-3.7.2.RELEASE\myFileName the toolsuite root location??? weird!!
Please tell me how to specify the relative path in a properties file.
Thanks!!
You can set the file path like any other string property in Spring Boot properties file and access it from inside the path.
E.g. I have the following set in my application.properties file:
download.directory=temp
and it is used as follows in java class:
#Value("${download.directory}")
private String downloadDirectory;
It is used to download the files, now, if I start the application with jar file present in let's say G:/applications folder then the files will be downloaded into G:/applications/temp.
So far we have been using Tomcat 6 where we specify the war to be deployed in context.xml file under $CATALINA_HOME/conf/Catalina/localhost as application1-context.xml, application2-context.xml. etc.
example application1-context.xml
<Context path="/myapps/app1" docBase="C:\warfiles\appOne.war"
debug="0" privileged="true">
<Loader className="MyCustomApplicationLoader"/>
<Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/>
</Context>
This would create a folder myapps#app1 under $CATALINA_HOME/webapps folder.
But since migrating to Tomcat7, this does not happen any more.
Unless I have the war file "appone.war" directly under the tomcat appBase directory i.e. $CATALINA_HOME/webapps my war will not be unpacked into a folder under $CATALINA_HOME/webapps directory.
I have read this apache bug report:
https://issues.apache.org/bugzilla/show_bug.cgi?id=51294"%3B>%3B51294<%3B/a>%3B
Question:
Is there any way we can force this behavior in tomcat 7?
It sounds like this issue has been fixed in Tomcat version 7.0.48 which, at the time of writing, is still in development. It's also been added to version 8.
Edit: I have managed to resolve this without having to wait for/use 7.0.48. In your context.xml file add unpackWAR="false" and specify the virtualClasspath attribute so it points to your target\classes folder like so:
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="(path to .war file)">
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
virtualClasspath="(path to folder contain .class files,
usually {project folder}\target\classes\)"
searchExternalFirst="true"
unpackWAR="false" />
</Context>
searchExternalFirst means that the class loader will look in your virtualClasspath folder before looking in the WEB-INF directory.
unpackWAR is set to false because your war file will already be exploded in the /target/classes folder so there's no need for Tomcat to do it as well.
Hopefully this helps you too.
Try <Context unpackWARs="true" ...
Files under conf/catalina/... should not be changed manual. They are created automatically if not exists on first start of the webapp. You should never change these files, delete them instead and let them be created new from tomcat itself (they are composed by the war's /META-INF/context.xml-File if exists).
I'm working on a project which uses JAAS and unfortunately for me Tomcat requires a file to be put in a META-INF folder in the root of the war
app.war
|__META-INF
| |___context.xml
...
I think that it's already weird since the default META-INF location for WAR's is in the classes folders.
app.war
|__WEB-INF
| |__classes
| |__META-INF
...
So I'm using Maven, which states that anything in src/main/resources/META-INF will be copied to the appropriate place, which it does. The weird thing is that it is also creating a META-INF folder in the root of the file structure leaving me with 2 META-INF folders.
Project Structure
app
|__src/main/java
|__src/main/resources
| |__META-INF
| |__context.xml
...
After mvn package
app
|__META-INF [1]
|__WEB-INF
| |__classes
| |__META-INF [2]
| |__context.xml
...
So, if the war standard states that META-INF should be under classes folder, as in #2, why maven war creates the #1 folder. And is there a way to make it copy files into that folder instead of #2?
Regards
So I found this:
Two Meta-Inf folders - normal structure?
which states that having 2 META-INF folders is not a problem. Digging a little I found:
JAR File Specification
which states about the META-INF folder:
A JAR file is essentially a zip file that contains an optional META-INF directory. ...The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services.
and this:
JSR-000315 JavaTM Servlet 3.0
which, on section 10.6, states about the WAR file structure:
When packaged into such a form, a META-INF directory will be present which
contains information useful to Java archive tools. This directory must not be directly
served as content by the container in response to a Web client’s request, though its
contents are visible to servlet code via the getResource and getResourceAsStream
calls on the ServletContext. Also, any requests to access the resources in META-INF
directory must be returned with a SC_NOT_FOUND(404) response.
So from the WAR spec the right place is WEB-INF/classes/META-INF. Yet, since war is a special jar file, it makes sense to have /META-INF as a point for extensions. One can see such different uses in JPA persistence.xml vs. Tomcat context.xml files: the former should be placed in WEB-INF/classes/META-INF while the latter in /META-INF.
How can I add META-INF/context.xml into the war? I didn't find any config entry in config/warble.rb.
Unfortunately Nick's method doesn't work. The file is actually copied to WEB-INF/META-INF/context.xml.
I finally figure out a way to copy context.xml to META-INF:
create META-INF/context.xml under your rails app root folder
uncomment and change the following line in config/warble.rb
config.public_html = FileList["public/**/*", "doc/**/*", "META-INF/context.xml" ]
Basically treat META-INF as public_html, and it will be copied to webapps/youapp/META-INF.
You'll have to add one yourself. You can either create a META-INF/context.xml directory and file in your project and add META-INF to config.dirs in config/warble.rb or you can add a "pathmap" to rename the context.xml file into the META-INF directory in the war file.
config.pathmaps.application += ["%{context.xml,META-INF/context.xml}p"]
A better way of tackling this might be to use the following in your warble.rb file.
config.script_files << 'path_to_file/context.xml'
See documentation towards bottom of https://github.com/jruby/warbler/blob/master/lib/warbler/config.rb
# These file will be placed in the META-INF directory of the jar or war that warbler
# produces. They are primarily used as launchers by the runnable feature.
attr_accessor :script_files