Best Practices for Java Deployments
The proper deployment of Java applications can be a cumbersome and tedious process, and the risk of failure has never been higher. Check out our best practices.
Join the DZone community and get the full member experience.Join For Free
The proper deployment of Java applications can be a cumbersome and tedious process and the risk of failure is never higher than it is the moment after deployment. Errors during/after deployment not only impact IT development and operations of the organization but also your customers.
To reach an optimal deployment process many projects and DevOps managers and engineers have adopted best practices to improve the deployment process to mitigate deployment risks. There is no silver bullet, but here are some best practices for Java deployment, which we will examine in this article.
1) Do a Reality Testing
Testing deployment in a pre-production/staging environment is essential (if not crucial) for success. Pre-production environments should be as similar to the production environment as possible. An ideal pre-production environment is composed of isolated hardware, software, and data that mirror a front-line production environment in every way. Typically, functional, regression as well as performance tests are conducted to ensure that the application still meets the requirements (functional & non-functional) once deployed in production.
The testing tools used in pre-production testing must be configured to resemble users’ activities using a complete user profile (simulating real production user activities).
2) Use an Artifact Repository
Today’s real-world of development, applications are not static binaries, but a collection of objects that have an inter-dependencies on each other. A JavaEE Web Application (WAR - Web Archive) may have dependencies of any kind of common functions, such as SLF4J, etc. and these dependencies have their versions. In a collaborative development environment, you want your developers to share the common libraries and the application can still be built and run in all your environments without breaking deployments (due to missing libraries or incompatible library versions).
Artifact repositories are great at managing multilevel dependencies. This dependency management is critical in reducing errors and ensuring that the right components are included with each build/deployment/release, especially in large scale applications. Also, you can apply the governance process to your artifacts such as security, licensing, etc. You can check out repositories such as Apache Archiva, Sonatype Nexus, Artifactory (by JFrog), just to name a few.
It is, therefore, essential that all your Java applications are versioned. For Mavenized Java projects, you specify your application version as well as declare your dependency in a
pom.xml file, specifying the source of your artifact repository and voila, your application (with its inter-dependencies are shared). This is particularly handy when applying a rollback strategy.
3) Have a Rollback Strategy
Should you ever find yourself in a position where a production deployment fails or your Java application introduces a (new) critical flaw/bug in your application, the best policy will be to rollback your application to a known working version of your application. It’s, therefore, essential that a rollback strategy is put in a place. One simple strategy is, if necessary, to backup your production application and, should rollback is initiated, undeploy the defected Java application and deploy the backup application. If you have an artifact repository you can simply redeploy a previous version of your application back to production.
There is no silver bullet for a rollback strategy. The Java team as well as the DevOps engineer should sit down and formulate what constitutes failure for rollback, the best rollback strategy, and document the rollback procedures.
4) Document, Document, Document
General practice for Java developers is to write code and documenting their code using code comment, highlighting the purpose and intent of the code. Documentation is your best friend. Before production deployment, make sure that you have a detailed and accurate document that lists the stakeholders of the projects, the features, and bug fixes introduced in your Java applications release, the backup plan, deployment plan, rollback plan, a maintenance plan, and communication plans & training plan (if needed). Furthermore, if your DevOps engineer ever leaves, the documentation can be used to retrace their steps and reproduce the deployment process they created.
5) Automate Your Deployment Process
Manual deployment is the least effective option for deployment as it can introduce errors, especially on a large scale and frequent deployments. One of the biggest challenges in Application Lifecycle Management (ALM) is dealing with the tasks of application deployment, various tools allow us to do an automated deployment. Make sure that you invest time in choosing the right deployment tool. For Java applications, factors to consider when choosing your deployment tool should include:
- Automated Build tool: Your Java application must be able to be built in the environment where deployment will occur effortlessly. Also, your build tool should identify dependencies between files and package them for distribution (Make sure that your deployment tool can integrate with your Artifact Repository). An automated build tool such as Apache Ant or Apache Maven is a well-known tool available for free for the project build.
- Load Testing and Performance Testing. Many application comes with performance KPIs & tools such as Apache JMeter, SmartMeter.io are suited for such purposes. Some of these tools can be easily be integrated into CI tools such as Apache Jenkins and/or Atlassian Bamboo.
- Automatic deployment. Make sure that the tool can deploy and install the application to the target environment.
6) Put the People First.
Deployment is not just a technological process but also a human process and it is a team effort for it to be successful. Most importantly, you have to include your stakeholders (inside and outside your organization) as well as your end-users. It is, therefore, crucial that you understand their requirements, needs, and expectations otherwise your deployment will be met with resistance. Communication is crucial in this regard.
Published at DZone with permission of BUHAKE SINDI. See the original article here.
Opinions expressed by DZone contributors are their own.
Hiding Data in Cassandra
Extending Java APIs: Add Missing Features Without the Hassle
Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
TDD vs. BDD: Choosing The Suitable Framework