maven deployment of configuration information to tomcat - java

In my current development/deployment workflow I deploy my (Java/Spring) web apps to a remote tomcat containers by using the tomcat7 maven plugin.
This makes easy for me to simply deploy the new version of my app by invoking
mvn tomcat7:deploy
My specific problem now is how to correctly handle configuration information: at the moment I keep configuration information (db connection info, passwords, etc.) in .properties files which are packaged with my war and then deployed remotely to the container as described above. An improvement of this process is the use of maven profiles to include different versions of .properties for different target deploy environments.
The problem with this approach is that sentitive information (eg. passwords) are packaged with the war file, while I would prefer to have them somewhere else on the server, visible to the web app (e.g. as part of its classpath), but manageable independently (so as to allow a change in some config settings withouth having to rebuild/redeploy the app).
The only solution I've found so far for this implies the following steps:
1) do not include the .properties in the packaged war
2) deploy the war to the remote server with mvn tomcat7:deploy
3) manually copy the .properties on some server folders where they are accessible from the web app via classpath
In step 3) "manually" means not using maven-based mechanisms for this step. Can someone suggest me some mechanism through which both the packaged war and the configuration files can be separately deployed to a remote server (for instance some ?

For example , you can do this :
1. Create module_config.zip with maven-assembly-plugin contains : *.properties
2. Deploy war with mvn tomcat7:deploy
3. Start script to copy module_config > dir_deploy_application
4. ReStart tomcat7
You can do it with (sh script) or (jenkins)

Related

Can I deploy multiple WAR archive files to local Tomcat with IntelliJ IDEA?

I have two applications with two separate WAR artifacts. One is a WAR exploded directory for my front-end Angular app, and one is a WAR archive file for my back-end Spring REST api. I'm currently using IntelliJ IDEA to deploy my front-end to a local Tomcat server and was wondering how, if at all possible, I could configure IntelliJ to run my two artifacts on Tomcat simultaneously. I know I can do this by putting both under Tomcat webapps directory manually, but I was wondering if it was configurable in IntelliJ, and if so, how?
Yes, you should be able to do that.
If you are using Ultimate, you can create a "Local Tomcat" run
configuration in Project1, and go to the "Deployment" tab and drop in
the WAR file for your Project1. Then drop in the WAR file from your
other project (call it Project2) as an External Source. You would
then have both WARs in one run configuration.
This is the answer I found out under this link.

How to configure properties and deploy application from Jenkins to tomcat

Is it possible to deploy a war file from Jenkins to tomcat with an application properties configuration?
Instead of building the war file from any version controll, I want to give a war file directly to Jenkins for deployment. Before that, some application properites(e.g., db connection, third-party services URL) will need to be configured according to the original deployed app and then deployed to tomcat. This might need to be done by writing some script?
For example, the deployed app is version 1.0 and db connection properties is port 5433. The war file which I gave is version 1.1 and the db port default is 5432. So, I have to update the properties in the war to 5433 for db port and deploy to tomcat to get a version 1.1 app and with correct db connectino settings(5433)
Does there have any plugin of Jenkins can achieve this?
Yes, you can do this through the scripts.
In the Build section of the Jenkins there is an option called Execute Shell - there you can do these things
1) Execute the script - which updates properties
sh script_with_changes.sh
2) Copy the war file as shown below using rsync command
rsync -avz /path/where/war/exists/xxx.war username#machineip:/tomcat/path/to/copy/xxx.war

How to export war with different file version to different deployment destination

I am use myeclipse to develop tomcat web application.
When I finish developing and decide to export war file to upload to remote server, I always have to change the configuration file like hiberante.cfg.xml, to connect to different mysql server.
Is there any way, like maven plugin or something that could keep two copy a resource like the hiberante configuration file. So when i export war I could choose like by profile or anything like that to include different version of a/some resources?
Appriciated.
That's usually the job of your config manager (Chef, Ansible, etc.) or at least the job of your source management tool (Git, SVN, etc.) to choose/contain the right config.
My quick way of deploying using Git is to have a git production branch that contains one extra commit (that is config changes); and for deploy I would just rebase the production branch from the working branch and deploy.

How to transfer file to server using maven

Once maven creates a WAR file (with mvn package) I would like to somehow transfer the war file onto another server and then execute a command on the server to deploy the war to tomcat. I am connected to the destination Windows 2008 Server via VPN. I can also ping the destination server while vpn'd in from my local machine.
Is there a way to do this transfer of the war from my local computer to windows 2008 server? Would I need to install something additionally on the windows server?
This blog entry details how to use the Maven Tomcat plugin to do this.
Issue “mvn tomcat:deploy” to package your project in a WAR file, and
deploy it to Tomcat server. To verify it, just access to the Tomcat’s
manager page and make sure “/mkyongWebApp” path is existed.
Basically you configure Tomcat to accept a remote deployment, configure your settings.xml with your Tomcat credentials, and set up the Tomcat Maven plugin with the hostname/port etc of your Tomcat server (phew!)
There are many ways, but none of them are ideal. I would personally discourage the use of Maven as a deployment or "devops" tool. If you really need to do this there's a good chance that your requirements are going to evolve and become more complicated as your application develops. Why not just start with CFEngine, Chef, Puppet, or other tools?
Warning aside, you could do the following:
Deploy with scp - The Maven Deploy Plugin can scp a file to a server. This overrides the real purpose of a deployment in Maven, but it will work. (Again the downside here is that you'll be overriding the real way that Maven was designed to work) For this to work you may need to explicitly add the SCP wagon provider, it used to be present by default, but it was removed.
Use Cargo to manipulate whatever server you use - http://cargo.codehaus.org/Maven2+plugin

Build Deployment basics

I am more into UI dev and less into Java...So, I would like to understand what exactly does the following things mean;
1. Build Deploy (Is it just a folder coped to a server and if yes, are there only class files in there,...)
2. What does exploded build mean?
If someone could explain me in very easy language (and not extremely technical), that would be really great...
Also any online resources in simple language would be helpful..
Thank you.
Build Deploy
Build deploy process will include many things such as
a) Checking the server configurations like database configurations, server resources configurations etc.
b) Checking the Application Configurations , means any changes in the application related configuration files.
c) Deplying the code on to the server
during this process server will read up the deployment descritor and deploy the application based on the configuration provided in DD xml (web.xml)
Also it deploy the ejb modules based on the configuration provided in ejb-jar.xml
Build Deploy
You build your application into some packaging and deploy it on the server.
for example if its web app you pack it in war file and put this war file on the server webapp for tomcat (dir differs from server to server) and start the server to deploy it.

Categories

Resources