Hello there friendly OpenShift Online Next Gen traveler. You are probably familiar with the Source-to-Image builder mechanism that allows you to push source code directly to the platform. Using this process is quick and easy in that it allows the platform to build the source and then create a new docker image for you on the fly. It truly seems like magic. What's that you say friendly traveler, you don't have an account for OpenShift Online Next Gen yet?
Well then, Sign up now!
However, one of the questions you may be asking yourself after using the developer preview for a few days is how to deploy a .war directly to OpenShift instead of relying on the platform to build your source code and resolve all of your dependencies for you (maven for example). I am happy to report that you can do this with just a few taps of the keys at your trusty command line using the oc command line tool.
If you just simply want to try this out if you don’t a .war file ready to go, I would suggest downloading the sample war file from the apache tomcat project to use as our example. Once you have the .war file downloaded and ready to go, we need to do a few housekeeping items.
First, create a directory for your project on your local file system. For example, I like to store all of my project in my ~/code directory so I would issue the following command (assuming sample.war is located in my Downloads directory):
$ mkdir sample
$ cd sample
$ cp ~/Downloads/sample.war .
Now that we a project directory created named sample, and our .war file located in the deployment subdirectory, it’s time to create our application.
$ oc new-app wildfly:latest~. --name mysample
This will create all of the necessary kubernetes and openshift objects required for our application. The last thing we need to do is to create a build that will push our .war file up to the OpenShift server and deploy it. Enter in the following command:
<span>$ oc start-build mysample --from-file=sample.war</span>
At this point, the file will be uploaded. Once it has finished, that last you need to do is create a route for your application so that it is available publicly.
<span>$ oc expose svc mysample</span>
Boom! That’s all there is to it. You can view the sample application deployed via a .war file by loading the route in your browser:
<span>$ oc get routes</span>
You will see output similar to the following:
NAME HOST/PORT PATH SERVICE TERMINATION LABELSmysample mysample-oncap.44fs.preview.openshiftapps.com mysample:8080-tcp app=mysample
In this case, my URL is mysample-oncap.44fs.preview.openshiftapps.com so I would enter in the following:
<span>http://</span><span>mysample</span><span>-oncap.44fs.preview.openshiftapps.com/sample</span>
What's next
OpenShift Online Next Gen is now in developer preview! For more information on how to use the platform or how to sign up, check out the following:
About the author
Browse by channel
Automation
The latest on IT automation that spans tech, teams, and environments
Artificial intelligence
Explore the platforms and partners building a faster path for AI
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
Explore how we reduce risks across environments and technologies
Edge computing
Updates on the solutions that simplify infrastructure at the edge
Infrastructure
Stay up to date on the world’s leading enterprise Linux platform
Applications
The latest on our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Developer resources
- Customer support
- Red Hat value calculator
- Red Hat Ecosystem Catalog
- Find a partner
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit