call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
How to Build & Deploy a HelloWorld API function using Java on OpenShift in 8 Steps
1. How to build & deploy
a HelloWorld API function
using Java on OpenShift
in 8 steps
Jan Vosecky
twitter: @jvosecky
2. In this tutorial
• For OpenShift beginners
• IDE: Eclipse
– no command line used
• Language: Java
• Goal: build and deploy a HelloWorld API function
3. Step 1: In Eclipse…
• Install Eclipse plugin for OpenShift
– Menu Help > Eclipse Marketplace
– In the search box, type: jboss tools
– Choose the plugin depending on your version of
Eclipse
4. Step 2: OpenShift.com
• https://www.openshift.com/
– Register account
– Login to your account, where you can:
• Create, manage, delete apps
• Find Quickstarts and deploy them
• Documentation:
– https://www.openshift.com/developers
5. Step 3: In Eclipse
• Create a new OpenShift application
– New > Project… > OpenShift > OpenShift Application
• Login with your OpenShift account
• Add your SSH keys
– If you don’t have SSH keys, the wizard can generate
them for you
• Add 2 new windows in Eclipse:
– Window > Show View > Other >
1. Git > Git staging
2. Jboss Tools > OpenShift Explorer
6. Structure of a Java web app
Your Java code (*.java)
Any other files needed by Java (config, txt, xml, etc)
Frontend (html, css, jsp, etc)
7. Step 4: HelloWord API function
package api;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = -3950937333898038206L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("name");
PrintWriter out = response.getWriter();
out.println("{"status":"Hello " + name + "!"");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Under folder: src/main/java/api/
8. Step 5: Add a dependency
– Similar to “include a library” in a desktop Java application
– Here we don’t include any JAR file, instead we point to a
central repository that contains *most* libraries
– Open pom.xml:
• Tab: Dependencies
• Seach for: javaee-web-api
– Wanna add other dependencies?
• Search for them: e.g., “mysql”