Can I run cygwin java through bash script?

507    Asked by LaurenHardacre in Java , Asked on Oct 10, 2022

 I've been encountering a problem with cygwin where I cannot run a jar file with an error that the file cannot be found.

If it were easier I would "translate" the java source in bash, but unfortunately, due to the functionality implemented, there are some quite significant obstacles to achieve this, so I'd have to use the jar file.

Now, I've done a fair amount of research on my part to figure out how to do this, however, I couldn't succeed, and it is mandatory that I use cygwin.

Here's what I'm trying to essentially do:

lockfile="$specialfolder/$passedargument.lock

java -jar `cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar -joption cygpath -w $lockfile`

i also tried with double back-ticks, as follows:

pathtooutfile="${some_other_vars}/${that}_${work}.out"

java -jar `cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar` -joption `cygpath -w $lockfile`

I also tried using the $JAVA_HOME env var but that did not work as well. It is important to mention that the variables being called in lockfile var are defined as follows:

homedir= "/cygdrive/driveletter/folder/folder"

 specialfolder= "$home dir/folder/$passedargument"

 passedargument= $1 ###argument passed with execution of bash script

 lockfile= "$specialfolder/$passedargument"

The error I keep getting is this: Error: Unable to access jarfile I have modified usage rights to 777 and that didn't work either. It might also be important to mention that -joption is either -aquire or -release corresponding to the lockfile since one of the things the jar does is manage multiple script executions through a lock file. I'm somewhat stuck, so any suggestions will be greatly appreciated. I think that this might be more of a cygwin issue.


Answered by leah D’Costa

If your expression


`cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar`

has embedded blanks, you should put double-quotes around it so that the result is passed to Java as a single token. It can help to understand the expressions and results if you turn on the shell trace, e.g., set -x.

Further reading:

cygpath — Convert Unix and Windows format paths, or output system path information

Making Cygwin java and Windows cooperate



Your Answer

Interviews

Parent Categories