javaautomationinstallationcommand-line-argumentscommand-prompt

How to install java through windows command prompt?


I was working on a testing team where we conducted end-to-end application testing. Each time before testing, I had to install and uninstall different versions of Java manually. We attempted to automate this process using AutoIt but were unsuccessful.

I’ve heard that Java can be installed and uninstalled through the command prompt, but I’m not sure how to do this.

I use Windows with various versions of Java. Could someone guide me on how to install and uninstall Java via the command prompt to reduce manual effort?

Thanks in advance.


Solution

  • In order to install java silently you can simply make a batch file(.bat) with the following command

    javaSetup.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature" INSTALLDIR=C:\Java\x86\ javaVersion /INSTALLDIRPUBJRE=C:\Java\x86\ jreVersion

    A proper example for above skeleton will be

    Here JDK 1.8.60 (x86) with source code is going to C:\Java\x86\jdk1.8.0_60 and JRE to C:\Java\x86\jre1.8.0_60:

    jdk-8u60-windows-i586.exe /s ADDLOCAL="ToolsFeature,SourceFeature,PublicjreFeature" INSTALLDIR=C:\Java\x86\jdk1.8.0_60 /INSTALLDIRPUBJRE=C:\Java\x86\jre1.8.0_60
    

    Just make sure you keep the batch file in the same directory as your setup file