Spring Boot on Android? - java

Is it possible to run Spring Boot on an Android device?
Right now I am successfully running a web service on localhost using Spring Boot which I've got building in IntelliJ IDEA. I need to get the same web service code running on an Android device. Is it possible to build the web service app into a JAR file that I can get running on an Android phone? I have a Google Nexus 6P running Android Nougat. I've done some limited research, and have found an application called JBED. So far I haven't been able to get this working.
I've started from scratch and built the example JAR:
gs-spring-boot-0.1.0.jar
and hopefully I can find a way to run this JAR. I'm guessing it probably won't work so if anyone has a better idea that would be great!

You can use i-jetty to host servlet based apps in android. or embed i-jetty (replacing tomcat or netty) in your spring boot app

Short answer is you're not gonna be able to directly run your spring boot application on your android phone. Spring boot is meant as a wrapper to quickly bootstrap Spring applications and is going to best serve you when building web based applications. As I see it you have two options.
Deploy your jar on the cloud somewhere(ec2,digitalocean, heroku, cloud foundry, etc.) and just access your Spring MVC app from the android browser. If you have some really complex logic in your boot app that you don't think you can port to android, you can still deploy your boot app in the cloud, and create a really "dumb" front end android application that consumes all of it's data from the spring boot app running externally.
Port you current spring boot application to a true Spring for Android project. http://projects.spring.io/spring-android/. The tools are out there to help you port it over all you have to do is put the work in.

There's an AnLinux app in play store that helps install a Linux distro inside termux.
I was able to install open jdk, spring cli and then run an spring boot project in that.
Here's a video I recorded demoing the same - https://m.youtube.com/watch?v=n9CY2wZPWJ0&t=1s

Related

REST API Deployment for Spring MVC

Currently I'm learning to build a REST API (backend) with the ionic application (frontend), but I'm facing an issue in backend REST API deployment. Thus, I'm asking this question to get some clues and answers related to REST API deployment, since I'm really new and no clue how to deploy a REST API. I had checkout some tutorial on youtube, but it seem like most of the example in videos are not using the technologies or environment that same as the REST API I built. The following shown the technologies I used to built my system frontend and backend:
REST API (BACKEND):
Language: Java, Spring MVC Framework
Database: Hibernate, Oracle SQL Developer
Web App Build Technology: Gradle, Gretty (To app start my application)
Ionic Application (FRONTEND):
Technologies: Angular Framework, HTML, CSS
How the application is working in localhost?
STEP 1: I will app start using Gretty plugin in gradle
STEP 2: I active the command "ng serve" (ionic serve) to run my ionic application
STEP 3: After both frontend and backend is successfully run, now I can access the provided link that generated from ng serve to access my web app and do anything I want.
Everything is working perfectly in local system, but it is different case when I test my ionic web app through my smartphone (Since ionic allows us to build progressive web app). The frontend ionic application will not able to communicate with backend when the operating environment of frontend is not in local system and I know it's really make sense, since my backend REST API haven't deploy which only able to operating on localhost. Therefore, I'm have tried to find solution on youtube and other internet sources to deploy my rest api online, but I don't see any information or deployment video that using the same technologies as I used to built my rest api (Spring MVC, oracle developer, gradle).
Thus, I'm asking this "stupid" question in here to find out whether any solution to deploy my rest api? or any suggestion to change the technologies that I used to built my rest api? or any mistakes I had made which violate the best coding practice in building rest api.
As a new programmer, I really appreciate the answers from all you guys. Thank you.
First, let's explain some concepts:
You backend is the application you coded, deployed on a server that exposes an endpoint for access - e.g. http://localhost:8080/yourApp - where your host/domain is your current computer (localhost) and the port is 8080 or anything you setup.
If you want to access from you smartphone:
1) Since your app is hosted on your pc, you need to be connected to the same wifi network
2) From your host machine, where you deployed your app, look for your ip address.
open your console/terminal
type ipconfig/ifconfig
look for your wifi and copy ipv4 address
3) redeploy your frontend pointing to your host machine ip
It worked before because you where on the same machine (localhost means redirect to your own device). When you switched to your phone it, also, redirects to your own smartphone.

Java spring boot as a windows service alternative

I have multiple spring boot projects that a running on windows server. For now I am deploying each project as a windows service because we cant use docker.
Now I was thinking about to reduce the amount of windows services that I have but not change the microservice architecure.
One alternative is OSGi which seems to be very nice but as I have seen it is not recommend to use spring boot apps with OSGi.
The next alternative I was thinking about was to create my own java "controller app" that then can start/stop the other microservices. So only the "controller app" has to be deployed as a windows service.
Is there a better alternative instead of creating a own "controller app"? Docker would be nice but unfortunately we canĀ“t use it. Or should we maybe try to run our spring boot services with OSGi?

Can i deploy my Java Spring-Boot Application in my Synology NAS?

I have a Spring-Boot Application with REST API (Maven build and MongoDB Database). I will also make a UI with Angular 2 on top of that (npm build).
What i would like to do is, to host this site, with its backend & database on a server. Can i do that on my Synology NAS (DS216j)? Or should i better buy a small computer like Raspberry Pi 3?
I have heard somewhere that we can deploy our apps in Docker, and Synology has a docker app or sth? Will this help me reaching my goal? I would like to have a step by step guide from your similar setups.
As far as I understand, you only want to get your app running on your NAS, so using Docker would be an option, but no requirement.
According to the model-specific download page, your DS216j supports Java8.
So what you have to do:
Install Java on your NAS
Package your application as standalone jar-file: If not yet done, you can do that in your pom.xml (see Spring Boot documentation for details; btw, this standalone mode is one of the best features of Spring Boot)
Now you can upload the jar-file
Run it via the command line with java -jar <jar-file-name>.jar
Just make sure that the port of your app does not conflict with the ports used by your NAS.
You could also create a Docker image from your app and run it on your NAS, it seems like your model supports Docker: https://www.synology.com/en-us/dsm/packages/Docker. But that would create some extra effort, but no added value, from my point of view.

Deploying Akka HTTP to Azure

I was looking for some info on how to deploy Akka Http app to Azure. Azure supports Java Web Apps, but I assume it does only for apps that run in TomCat or alike. But Akka Http is a standalone application - is there any support for that and in any case, how should I proceed with it?
I am aware of sbt-native-packager that can produce various installable formats, but seeing how easy it is to deploy .NET app from Visual Studio, I would love to see a simpler way for Java as well.
Based on my understanding, your app using Akka Http is a standalone jar file which need to be deployed on Azure WebApps. Please refer to the section Application configuration Examples of the offical tutorial Upload a custom Java web app to Azure to create a web.xml file in the path wwwroot to deploy your app like these samples Jetty or Springboot.

Bluemix: Java Rest API starter app

I want to run and deploy a java rest API code on Bluemix. This is more to understand the Devops capabilities in conjunction with API management.
I tried to use this: http://www.codingpedia.org/ama/tutorial-rest-api-design-and-implementation-in-java-with-jersey-and-spring/
But could not push it to Bluemix. May I get some support?
Update:
When I push it to Bluemix, I get an error saying it could not find appropriate runtime.
Reading your comments you are searching for some pointers to create a starter Java REST application (possibly integrating a delivery pipeline).
You can start creating an application on Bluemix using the Liberty for Java runtime. Then you can, from your application dashboard, click on "Add Git" to create a Git repository on IBM Bluemix DevOps Services (IDS). Now you have your starter application running on Bluemix and its code hosted on IDS. You can edit the code directly on the Web IDE of IDS (clicking on "Edit Code") and from there push the new versions of the applcation on Bluemix or you can clone the repository on your local environment (for example using the Eclipse Tools for Bluemix) and deploy directly from your machine to Bluemix.
Using the first option you will be able to quickly setup a delivery pipeline using the "Build & Deploy" button, and use the DevOps capabilities of IDS. The Build & Deploy feature, also known as the pipeline, automates the continuous deployment of your projects. In a project's pipeline, sequences of stages retrieve input and run jobs, such as builds, tests, and deployments.
To add REST capabilities to the sample application you can for example use JAX-RS 2.0. Take a look here.
Javaee jax-rs REST API starter
Use my java REST API starter for bluemix. This uses javaee + jax-rs + swagger
Just fork it, run pom.xml to generate war and push the war file to bluemix. Works like a charm
https://github.com/sanketsw/jax_rs_REST_Example
Spring boot REST API starter for bluemix
if you want a spring boot REST API starter, you can use the following boilerplate. This is a netflix eureka client but you can ignore eureka annotations. The REST API will work seamlessly anyway
https://github.com/sanketsw/Netflix_Eureka_Client_Hello_World
Another cleaner springboot REST API starter is here: https://github.com/sanketsw/SpringBoot_REST_API

Categories

Resources