How to detect java installation from a batch program - java

I want to run a jar file on a client machine using batch script. But the problem is its not clear where is the java installed. There are 3-4 fixed paths where java.exe can exist.
How to write a batch script to find where java is installed on any of those predetermined locations and then run a command to execute a jar file.
Assume java is not set in the environment variables and no access to windows registry.

On windows :
c:\> for %i in (java.exe) do #echo. %~$PATH:i
On linux:
$ which java

Related

How do I find where Java is installed on Windows 10?

I recently installed Java (Java Runtime 1.8.121) to my machine. I need to set up JAVA_HOME and set the variable from the Java folder where it installed.
Everywhere I have looked online says the Java folder should be located in Program files (x86), however, it is nowhere to be found. Its not in program files (x86), not in program files.
I wasn't able to choose a destination when it was installed as Software center was used. It simply completed the installation.
Can someone please help me find where the Java folder is so I can set up JAVA_HOME???!
cmd:
where java
git bash (same as cmd or):
which java
powershell:
(get-command java.exe).Path
Superuser: Equivalent of cmd's "where" in powershell
Open a command prompt
type: wmic product where "Name like '%%Java%%'" get installlocation,Name
This command can take a minute to complete. But should return something like this.
Edit: The benefit of this command, is that it doesn't rely on any system environment variables. It searches for installed programs that have the word 'Java' in the name. It won't return extra files or locations.

Why are some Cygwin files not executable?

I'm attempting to execute Cygwin commands on Windows from a Java application. In cygwin's bin, I noticed some files are Application type (.exe) while others (like zcat and zless) have no extension and are just File type.
I've added the bin to the Windows PATH and seem to only be able to execute the .exe files from cmd. The code below works.
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "ls");
Process p = pb.start();
I want to use things like zcat and zless but they aren't executable and cmd complains that 'zcat' is not recognized as an internal or external command,
operable program or batch file.
If I manually change the file to .exe, I get a pop-up error saying zcat can't start or run due to incompatibility with 64-bit versions of Windows. I've installed the 64-bit version of cygwin (setup-x86_64). Why isn't all of cygwin's bin executable?
Most of the cygwin programs are NOT binary program but script one.
The command file can give you a description of the file type:
$ file zcat
zcat: POSIX shell script, ASCII text executable
while
$ file cat
cat: PE32+ executable (console) x86-64, for MS Windows
reading the first 5 rows of zcat
$ head -n 5 zcat
#!/bin/sh
# Uncompress files to standard output.
# Copyright (C) 2007, 2010-2016 Free Software Foundation, Inc.
we see on first row the #! that says that is a script to be executed by the
/bin/sh interpreter.
In other case we can have
$ head -n5 2to3
#!/usr/bin/python2.7.exe
import sys
from lib2to3.main import main
sys.exit(main("lib2to3.fixes"))
so 2to3 is a python 2.7 script
Nobody else has said this, so for anybody else looking for this ... if you need to run the "z..." commands from the cmd window AND you have the cygwin bin directory in your path, you can run them (yea, it's a bit klugy) using bash, as in
bash zcat file.gz
etc.
Or you can run them directly from the cygwin terminal.
FWIW I had to find the 'more' utilities and load them. For some reason they weren't in my initial set of packages I downloaded

Bash, Windows 10, Java - No such file or directory for Java application

I'm trying to execute a Java file I was given on Windows 10, inside of the Bash shell.
I open my command prompt. I enter bash.
I set
JAVA_CALL="C:/Program Files/Java/jdk1.8.0_192/jre/bin/java"
I try to execute the call, but to no luck. I read several threads on here and tried several things. I made sure my path includes both the Program Files x86 and the regular Program Files version of my JAVA.
I executed
sudo ln -s -f /mnt/c/Program\ Files/Java/jre1.8.0_192/jre/bin/java.exe /bin/java
To try and make a link to it. I cannot get it to wrong. It always tells me
-bash: C:/Program Files/Java/jdk1.8.0_192/jre/bin/java: No such file or directory
I am sure that file exists. Any ideas?

MAC OS - Terminal command to set JAR program to run at startup?

This is where MAC OS stores its start-up items,
/Library/LaunchAgents
How to set a JAR program from Terminal to run at startup? Also how to remove existing program from startup?
I need to use either Terminal or any other script code to add JAR program to load at startup.
Write a bash script that runs your JAR.
#!/bin/bash
java -jar /path/to/my/jar
Create a .plist entry in /Library/LaunchAgents as shown here

java virtual machine launcher error: unable to access jarfile

I have downloaded a program to run on windows XP.
According to the instructions, opening the .bat file that includes the command that calls the .jar file would be enough.
Yet the program does not open.
In a friend's computer the program does open.
I have set correctly the java-related environment variables. Java works fine. I have associated .jar files with java sdk.
When calling the command
javaw -Xms128M -Xmx512M -jar filename.jar from cmd
I get a java virtual machine launcher
error: unable to access jarfile
Then I called the same command while being on the folder where the jar is, I have no error, but still the gui of the program does not open.
Any ideas?
On windows support the suggest unistalling and manually re-installing java, but java works fine in any other app.
Try some of the following:
Run directly from the .exe, so "C:...\jre\javaw.exe" -jar
Try java -jar instead of javaw -jar.
Try moving the file. It could be in a permissions sensitive directory.
Also, if the program was compiled using a 64-bit JDK, it might require a 64-bit JRE to run. In that case, you'd need to have a 64-bit OS/JRE to run it.

Categories

Resources