Run Java Console Applications in the Cloud

| DevOps PaaS | September 17, 2012
Last week we shared with you the addition of the IaaS feature VDS to Jelastic PaaS. Today we'll show you how to use this add-on to run your java console applications. Let's check out some of the main uses of console apps.
Java Console application can only display textual data, but despite that, they are still quite good for applications that have limited user interaction. If a program has to run in the background, without user interaction, a console application is the best choice. Typically, background applications are written as console applications, for example: anti-virus programs that scan while the user is doing other work or business data processing programs (loading applications that process large volumes of data). Console applications are also great for setting up quick tests to see how Java works.
Now let's go though the steps below to run your Java Console app in the Jelastic Cloud.
Note: this feature is available starting with Jelastic version 1.8.2 and is a paid add-on.
Create a new environment and establish an SHH connection as it is described here.

Install Java to VDS

1. Go to VDS node as root using the established SSH connection. Enter the following commands:
wget {utility_address}
rpm -ivh {java_rpm_package}
2. To check the installation enter the command:
java -version

Create Java application

1. Create your Java Console application.

2. As an example we use app, which is going to listen to the connections on your port. Here you can see our Java code:

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
public class VdsSocket {
public static void main(String[] args) {
try {
int port = 7777;
InetAddress thisIp = null;
ServerSocket ss = new ServerSocket(port);
System.out.println("Socket Listener listens port: " + port);
while (true) {
Socket s = ss.accept();
String address = s.getRemoteSocketAddress().toString();
System.out.println("new client has been detected:");
System.out.println("Socket. Remote Address: " + address);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
oos.writeObject("Request time: "+ new Date());
oos.writeObject("Socket. Remote Address: " + address);
} catch (IOException ex) {

Upload application to VDS

1. Now you need to upload the .jar file of your Java application to VDS. As an example we'll use vdssocket.jar.

2. For uploading we use WinSCP (SFTP, SCP, and FTP client for Windows).
Before starting you should:

  • Install WinSCP ;
  • Connect to your VDS using credentials which you've got while creating the environment.
3. Once you are connected to your VDS, you can see the content of your home directory on remote file panel. Create a new folder and navigate to it.
In our case:

4. Now you can simply drag the .jar file and drop it in the remote file panel. By default, the transfer settings dialog will appear. Just press Copy and the upload will start. Once it is finished, you will see uploaded file in the remote file panel.

Configure application in VDS

1. Go to VDS node as root using the established SSH connection.
2. Open the folder with the .jar file you'?ve just uploaded. For that use the next commands:
cd /
(to open root directory)
(to see the structure with all the folders and files)
In our case we have:
3. In the opened folder enter the following command:
java -jar application_name.jar
In our case we have:

Check the work of standalone application

1. To check if your application is working, install Telnet (in Windows operating system, Telnet client application software is included to provide telecommunication network capability) and enter the following command for getting Telnet connection with your VDS:
o IP port_number
In our case we have:
2. After that, if everything is alright you'?ll get a message with information about the Request time and Remote address.
3. Also you can see the logs in VDS form. If a new client connects you'll get the information about his Remote Address.
That's all. Now you can freely use your Java console application!
Related article: