🌐
Linux Hint
linuxhint.com › run-java-command-line-linux
How to Run Java from Command-line in Linux – Linux Hint
To run the java program in Linux, we need to verify if Java Development Kit (JDK) is available in the system and its version.
Discussions

Running Java Program from Command Line Linux - Stack Overflow
I am not very experience with java and this is driving me crazy. I wrote a java program FileManagement and I need to run it from the command line. I can compile it from the command line with javac More on stackoverflow.com
🌐 stackoverflow.com
How to run Java application on startup of Ubuntu Linux - Stack Overflow
I successfully made the program as Java program with No GUI means as soon as program runs it starts listening to the Socket and gets the response with the help of Netbeans IDE. Now as per my requirement i have to start execution of this program as soon as Linux system Booted. More on stackoverflow.com
🌐 stackoverflow.com
How to start a .jar file using Java on Ubuntu
The first time I tend to run it in a shell with java -jar just to see any possible error messages. Plenty of times I was missing some java package dependecies and the error messages are a good hint at what is missing. (But I guess your can do that with OPs guide as well by using "Run in terminal" or whatever the option is called in your DE) More on reddit.com
🌐 r/linux_gaming
4
5
October 3, 2024
Run a Java Application as a Service on Linux - Stack Overflow
I have written a Java server application that runs on a standard virtual hosted Linux solution. The application runs all the time listening for socket connections and creating new handlers for them. It is a server side implementation to a client-server application. The way I start it is by ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
It's FOSS
itsfoss.com › run-java-program-ubuntu
How to Run Java Programs in Ubuntu
January 11, 2023 - Installing JDK that also contains the Java compiler · The above command should work for other Debian and Ubuntu based distributions like Linux Mint, elementary OS etc. For other distributions, use your distribution’s package manager.
🌐
DZone
dzone.com › software design and architecture › cloud architecture › how to make it easy and simple to start java processes in linux/docker
How to Make It Easy and Simple to Start Java Processes in Linux/Docker
July 5, 2018 - In short, let's look at the example of the Nexus 3 mentioned above, how to return from the labyrinth of shell scripts to something more similar to java -jar <program.jar>, given the convenient modern DevOps-tools. In a nutshell, in ancient times, when UNIX was not interrogated at the mention of "in the sense of Linux?", there were no Systemd and Docker, etc. To manage the processes, we used portable shell scripts (init scripts) and PID-files. Init scripts set the necessary environment settings, which in different UNIX-s were their own, and, depending on the arguments, they started the process or restarted/stopped it using the ID from the PID-file.
🌐
Linux Journal
linuxjournal.com › article › 6290
Getting Started with Java on Linux | Linux Journal
August 26, 2002 - Write once, run everywhere: that's the slogan the Java community uses to propagate their language-of-choice. It's probably true, but only if you first manage to set up the beast on your box. This article gets you started with Java on Linux by showing you how to get the Java Compiler and Virtual Machine installed so you can run core Java programs.
🌐
LinuxForDevices
linuxfordevices.com › home › how to run a command-line java program on linux?
How to Run a Command-Line Java Program on Linux? - LinuxForDevices
July 19, 2021 - In this tutorial, we will learn about how to run a command-line Java program from the Linux terminal.
🌐
The Art of Code
artofcode.wordpress.com › 2025 › 01 › 14 › running-java-application-as-a-linux-service
Running Java application as a Linux service | The Art of Code
April 1, 2025 - This post is a continuation of my previous one, "Turning a laptop into a Java app server in 2025". In this part we're going to setup a Java application as a service in Linux. We will use Systemd for this so a service will be automatically started on system boot and it will be run…
Find elsewhere
🌐
Princeton CS
introcs.cs.princeton.edu › java › linux
Hello World in Java on Linux
August 14, 2019 - This document instructs you on how to setup a Java programming environment under Linux. It also provides a step-by-step guide for creating, compiling, and executing your first Java program using either DrJava or the command line. We assume some familiarity with the command line.
🌐
Baeldung
baeldung.com › home › administration › service management › run a java application as a service on linux
Run a Java Application as a Service on Linux | Baeldung on Linux
March 18, 2024 - No ads, dark-mode and 6 months ... to start with. Any Java application from the system point-of-view is just an instance of the Java Virtual Machine. In this short tutorial, we’ll see how we can make our applications run as system services. We’ll use the facilities of the systemd software package. systemd is the initialization and service management system in most modern Linux ...
🌐
Oracle
java.com › en › download › help › linux_x64_install.html
Linux 64-bit installation instructions for Java
Unpack the tarball and install Java tar zxvf jre-8u73-linux-x64.tar.gz The Java files are installed in a directory called jre1.8.0_73 in the current directory. In this example, it is installed in the /usr/java/jre1.8.0_73 directory.
🌐
DEV Community
dev.to › mtendekuyokwa19 › setting-up-for-java-on-linux-133f
Setting Up for Java on Linux. - DEV Community
February 14, 2024 - Firstly, congratulations for using a great open source software,Linux. To get started I will have to explain the two main components you need to have Java up and running on your machine. You will need the Java development kit (JDK) and an IDE.
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › download-install-java-windows-linux-macos
Installing Java on Windows, Linux, and macOS - GeeksforGeeks
April 20, 2026 - Installing Java is the first step to start Java development on any system. It allows you to run Java applications and build projects across different operating systems. Java can be installed on Windows, Linux, and macOS using platform-specific steps.
🌐
Princeton CS
introcs.cs.princeton.edu › java › 15inout › linux-cmd.html
Java and the Linux Command Line
August 14, 2019 - You will use the Java compiler javac to compile your Java programs and the Java interpreter java to run them. We'll assume you have already installed these. You will type commands in an application known as the shell. Since you're using Linux, we assume you're somewhat familiar with it.
🌐
Opensource.com
opensource.com › article › 19 › 11 › install-java-linux
How to install Java on Linux | Opensource.com
$ tar --extract --file openjdk*linux-x64_bin.tar.gz \ --directory=$HOME/bin · Java is now installed.
🌐
Reddit
reddit.com › r/linux_gaming › how to start a .jar file using java on ubuntu
r/linux_gaming on Reddit: How to start a .jar file using Java on Ubuntu
October 3, 2024 -

Ok, i just spent way too much time on trying to figure this out. Hopefully this will help someone who's searching for a solution to this same problem. I have Lubuntu 24.04, this instruction is for this system but will probably work for other Ubuntu OS versions.

To start a .jar file using Java, right-click the file in a file manager (in my case, PCManFM-Qt),

click "Open With...",

choose the "Custom command" tab,

in the "Command to execute" field, enter "java -jar" (only the bold text, without the quotation marks),

Also you can choose the option "Set selected application as default for this file type" or something like that so every .jar file gets opened by Java. But that's if you want your system to do that.

Also it helps to enter the Application Name in the appropriate field so that it's not just empty when you select the "Open with..." option in your file manager.

Then click "OK".

I'm not very knowledgeable on Linux in general, but this worked for me and hopefully this will save someone some time and they won't have to figure it out like i had to.

Top answer
1 of 16
244

I wrote another simple wrapper here:

#!/bin/sh
SERVICE_NAME=MyService
PATH_TO_JAR=/usr/local/MyProject/MyJar.jar
PID_PATH_NAME=/tmp/MyService-pid
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
            nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
            echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stoping ..."
            kill $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill $PID;
            echo "$SERVICE_NAME stopped ...";
            rm $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &
            echo $! > $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
esac 

You can follow a full tutorial for init.d here and for systemd (ubuntu 16+) here

If you need the output log replace the 2

nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null &

lines for

nohup java -jar $PATH_TO_JAR >> myService.out 2>&1&
2 of 16
52

A simple solution is to create a script start.sh that runs Java through nohup and then stores the PID to a file:

nohup java -jar myapplication.jar > log.txt 2> errors.txt < /dev/null &
PID=$!
echo $PID > pid.txt

Then your stop script stop.sh would read the PID from the file and kill the application:

PID=$(cat pid.txt)
kill $PID

Of course I've left out some details, like checking whether the process exists and removing pid.txt if you're done.

🌐
Apryse
fluent.apryse.com › running on linux
Running Java Engine on Linux | Fluent Docs - Apryse
This article explains how to install and use the Fluent Java Engine in Linux. This tutorial specifically uses Ubuntu Server 18.04 LTS, but the steps should work on any Linux system with little extra effort.