Dec 19, 2019 - Spring Boot Deployment

Spring Boot Deployment on a server

Well, it took longer time than I thought to deploy my Spring Boot application to the server. Deployment itself was easy enough but what I wanted to do brought a little bit complicated tasks. My goal was all traffic is encrypted by SSL and application can be subdomain becasue there is a website running under SSL.


  • Use Tomcat on a server, not with Spring boot.
  • Setup SSL configration with Apache, then use ProxyPass to pass the trafic to tomcat.
  • Application class which is annotated @SpringBootApplication needs to extend SpringBootServletInitializer. Look here.


  • Apache 2.4.x
  • Tomcat 8.x
  • IntelliJ 2019.3
  • Gradle 5.6.x
  • CentOS 7
  • Java 8

First, just deployment

To deploy a spring boot application to a server is easy enough. * I will not mentioin how to make Spring applicatioin or gradle configuration here.

Once you create your application with gradle, just run build to make .jar file.

gradle build   # or gradlew

You should be able to get a jar file under build/libs/ directory. You need to copy this jar file to your target server.


java -jar yourjar.jar

You should be able to access with domain or ip address with port 8080. If you have an index or controller for “/”.


URL is ugly using port nunber

I think URL using port number is ugly and did not want to a port for that. So I searched a solution.

ProxyPass with ajp

Tomcat has AJP connector to communicate via AJP protocol. Some website says that you can use mod_proxy to forward traffics to tomcat with ajp.

ProxyPass / ajp://domain

But it did not go through. Some of error message indicated that cannot pass traffic to tomcat properly because of having SSL.

For Spring application configuration, I reffered this website to set up my application. I tool so many hours to figure this out but it does not make my web app work. * This website information is kind of old so you need to change some code, such as TomcatEmbeddedServletContainerFactory.

Gave up using buit-in Tomcat

I gave up using Spring boot built-in Tomcat because I wanted to have more apps to the same server so I had a plan to deploy Tomcat on the server anyway.

To use Tomcat on a server, you should use war file instead of jar file. You can just add these lines below.

plugins {
	id 'war'

and run

gradle bootWar

You should get war file under build/libs/ directory.

I installed Tomcat 9 to my CentOS server. Default CentOS7 yum try to bring Tomcat 7. If you want to have the version you want, just go and check Tomcat website to download files. This was useful.

My server does not have Desktop environment so I did not use GUI management for setting up and deploy war files but these are easy with CUI. References: #1 #2

If you set autoDeploy=true, you just need to copy war file to whereever your configuration under the root directory of applications. usually, webapps.

Wait, showing 404

Long story short, you need to change your Spring Boot app if you made it for jar file with built-in server. Please see here.

public class Application extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);


Then, your application should run on Tomcat on the server.


Since I run apache and tomcat on the same server, I just set up subdomain’s all port 80 traffic to 443 and the VirtualHost has

ProxyPass /appname/ http://localhost:8080/appname/

so that these traffic can be passed to Tomcat. I know this is bad practice but I did not want to build another server for just testing.

If web server and application server are separated, you should not use this because traffic between web server and application server is not encrypted.

Sep 1, 2019 - Android Activity


Basic ideas here

  • FirstActivity -> NextActivity
    • Make Intent
    • Set Extra
    • call startActivity(Intent)
  • FirstActivity -> NextActivity -> FirstActivity(Back)
    • In FirstActivity
      • Make Intent
      • Set Extra
      • call startActivityForResult(Intent, requestCode)
        • requestCode has to be an integer greater than zero.
    • In NextActivity
      • Make Intent
      • Set Extra
      • Set resultCode and Intent with setResult(requestCOde, intent)
      • call finish()

Simple Activity change

When you want to change screen on your Android app, you need to call another activity.

When you want to change activity, you need to use Intent class and startActivity(). When you want to pass the data, you can put Extra to Intent.


Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("com.yourdomain.appName.MESSAGE", "Message here!");

NextActivity.java To get the message from MainActivity.

Intent intent = getIntent();
String str = intent.getStringExtra("com.yourdomain.appName.MESSAGE");

When your activity comes from another activity

When your activity comes back from next activity. You need to use startActivityForResult.


Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("com.yourdomain.appName.MESSAGE", "Message here!");
startActivityForResult(intent, 1); //startActivityForResult(Intent, requestCode)

Request code should be unique and best practice is declare static final int in the class. You need to select a number greater than zero for the requestCode.

When you want to go back to the activity you came. NextActivity.java

Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("com.yourdomain.appName.RETURN_MESSAGE", "This is return");
setResult(Actibity.RESULT_OK, intent);

MainActivity.java Once active actibity returns previous activity, onActivityResult is called.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 1) {
        if(resultCode == Activity.RESULT_OK){
            String result=data.getStringExtra("com.yourdomain.appName.RETURN_MESSAGE");
        if (resultCode == Activity.RESULT_CANCELED) {

categories: [Java, Android]

Aug 17, 2019 - Android View Basics


Android app development

This is whole another story from JavaFX development. I got stuck at beggining.

You can learn basics from [Android Developer site].(https://developer.android.com/guide/) In my opinion, this is not the greatest but there are lots of important and good information. If you need more code samples, you need to look up online. You can also use kotlin but the way how to use APIs is almost the same.

I needed to understand their language first. I meant words that they use.


  • ViewGroup objects
    • A hierarchy of layouts(and containers)
    • ViewGroup can have children views(components).
    • Such as
      • LinearLayout
      • GridLayout
      • AdapterView
  • View objects
    • a.k.a widgets
    • Such as
      • TextView
      • ImageView
  • Constraints
    • You need to set constraints among each objects.
    • This is really important that set components on a layout.
  • Activities and Fragments
    • Presentation layer
  • ViewModel
    • Business Logic
  • Repository
    • knows where the date is stored.
    • Room library - local
    • Retrofit library - web


These are view xml files.


This is constant words list. When you want to show something on the button or other View objects, you should use this.


You need to descrie essential information about the app. Such as activity, service information.


  • The words that they use is different but basics of GUI application is the same.
  • Setting up calling method for action is almost the same as JavaFX.
  • Data sharing with the other view is simpler but there are some ways to do.
  • ListView handling is different.

categories: [Java, kotlin, Android]