Batch - Figure out if java is installed or not

303
June 12, 2017, at 03:42 AM

First to say, I am not experienced with batch-scripts at all.

As the title already tells, I am trying to figure out if java is installed on the system or not, from a bat-file. I already checked many ways to do so but most of them seem more complex than what it should take to get this done.

My idea so far was to save the result of java -version into a variable and then check if there actually was an result, or if the command java couldn't be found. Sadly I couldn't even figure out, how to get the output of java -version saved to a variable so i could compare it.

If someone can help me with my idea or has a different simple solution to my problem i would be glad if you could help me out. Thanks.

Answer 1

Try this instead:

where java >nul 2>nul
if %errorlevel%==1 (
    @echo Java not found in path.
    exit
)

The >nul and 2>nul are optional and used only to mute the where command output.

Answer 2

Try using java -version command in your script and saving it to a variable like this: isJavaInstalled="$(java -version)". If Java is installed, the variable should contain something like this: java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode), else the variable is empty. You can also try to check the value of JAVA_HOME system variable which should contain a path to where Java is installed.

READ ALSO
Is it a good idea to implement JsonDownloader separately?

Is it a good idea to implement JsonDownloader separately?

I am doing an android project where I need to send JSON requests in almost every activity for the reply from the serverSince I was warned that helper / utility classes are bad, I doubt if it is a good idea I write a non-static class outside of the hierarchy...

209
BorderPane won't show ListView JavaFx

BorderPane won't show ListView JavaFx

I have a window formed from a BorderPane at base, a VBox for the West Side where I place some labels, another VBox for the East Sidewhere I place a textfield and a ListView, a HBox with some buttons place in South

302
what is “arbitrary” native code in Android?

what is “arbitrary” native code in Android?

In Android Instant App documentation, it describes one of restrictions as below;

262
Retrieve Link from Website in Java

Retrieve Link from Website in Java

Is it possible to retrieve a changing download link from a button implemented in a websiteIs there any way to get always the updated link via Java code? Currently I do this manually using Firebase Remote config

276