Deploying Resources with Play! Framework - configuration

My web application uses MyBatis ORM. As a part of this, I have the typical mybatis.xml config file along with mappers for my SQL. When running the Play! server, the directory with these resources is not picked up and added to the classes directory.
Is there a way to configure Play! to include this directory in it's load/deploy process?

With Play 1.x the simplest way to do this is to put your files in the conf directory which is in the classpath

Related

Angular Project- Replace properties from External File in app.config.json

I have Angular 7 application. I'm building it and generating Dist package. I would like to deploy this package on Tomcat or Apache web-server.
Now, I do not want to hard-code any values in app.config.json file. I would like to externalize these properties. Let's say, i have server.xml file or any other file in tomcat and values should be there and app.config.json should read property values from there.
How can I achieve this? Is there any other way, I can externalize my properties?
Maybe this can help you https://itnext.io/how-does-app-initializer-work-so-what-do-you-need-to-know-about-dynamic-configuration-in-angular-718e7c345971.
Using this approach you can provide your configuration file directly to container (Tomcat or Apache Server) independently on environment.
If you use k8s, you can provide this config file through ConfigMap.

How can I define an arbitrary file outside my web application to configure log4j2

My web application will be deployed to Weblogic application servers on Windows and Linux/Unix in different environments. The log file location, appenders and log levels will vary between the different deployments and we would like to be able to change the logging configuration during runtime (by exchanging the config file), so I cannot embed a log4j2.xml (or whatever other config file) into my deployment. And since I'm running on Application servers I cannot control, I've got no chance to add environment variables to point to another configuration Location.
Currently, my log4j2.xml resides in the classpath of my application and is being packaged into my war file. Is there any way to tell Log4J2 to use a configuration file e. g. relative to the application root (like Log4J's configureAndWatch(fileLocation) method)?
I found lots of examples of how to configure Log4J2, but everything I found about the config file location points to the applications class path.
I finally found a solution for my problem. I added a file named
log4j2.component.properties
to my project (in src/main/resources). This file contains a property pointing to the location of my log4j2 configuration file:
log4j.configurationFile=.//path//on//my//application//server//someLog4j2ConfigFile.xml
This causes log4j2 to read that file and configure itself from it's content.

Package HTML, CSS, JS in Jar or ZIP

Is it possible to either pack only html, css and JS files in jar (no java binaries) which would then be packed into war for deployment to Tomcat?
or
Can I pack html, css, js files (no java classes) into a zip and pack it into a war for deployment to Tomcat? With this option, would Tomcat unpack the zip as needed?
If you are deploying to Tomcat (and there is presumably some java or JSP code associated with this) then you should use a .war file.
To incorporate purely web assets into the building of a .war, then you need to use an "overlay". There are various Maven plugins and Ant tools which do specifically this.
However, one other possible consideration, is to deploy your web assets directly to your HTTP server (ie. Apache) and then configure it to serve /css/*, /js/*, etc, from there, and every other request can be forwarded to Tomcat.

Methods to inject configuration into WAR archives?

I have a couple of not so nice Java applications. I know that those are just zip files that can be reassembled.
Is there some common tool (ant, maven tasks or somesuch) that is usually used to inject configuration?
If I need to update a configuration file, I use the jar command to extract the file:
jar xvf app.war WEB-INF/classes/hibernate.cfg.xml
Then, after I've updated the configuration file, I update the war:
jar uvf app.war WEB-INF/classes/hibernate.cfg.xml

Configuration path of Log4j2

I am trying to adopt Log4j2 to my project. Since my Java Application is packeted in a JAR file. I don't want "log4j2.xml" configuration packaged inside of JAR file. I am trying to learn how configuration file works from "http://logging.apache.org/log4j/2.x/manual/configuration.html"
But seems there is no clear instruction regarding altering the configuration file path of the Log4j2.
After googling about this topic I found something like "Referencing log4j config file within executable JAR" Referencing log4j config file within executable JAR, But this solution is not available any more according to "http://logging.apache.org/log4j/2.x/manual/migration.html" (if I understand it correctly).
So I am wondering if someone have any idea about this issue.
Thanks
You can set the system property to specify the configuration path.
set the
"-Dlog4j.configurationFile="D:\learning\blog\20130115\config\LogConfig.xml"
in VM arguments. replace
"D:\learning\blog\20130115\config\LogConfig.xml"
to your configuration path.
Put the log4j2.xml file in resource directory in your project so that the log4j will locate files under class path automatically.
Loading log4j2.xml file from the customized location-
You can use the System property/ VM arguments- Dlog4j.configurationFile=file:/path/to/file/log4j2.xml
This will work for any web application.
For some legacy applications, you can create a class for loading log4j2.xml/ log4j2.properties from the custom location on the machine like- D:/property/log4j2.xml
Using any of these approach,during application startup, the log4j2.xml file from the src/resources folder will be overridden by the custom location log4j.xml file.
Try using -Dlogging.config=Path_to_your_file